Creating and drawing huge (buffered) images in Java

I am working on an application that draws a matrix - using Java 2D - which can become quite large, such as 30,000 x 30,000 pixels. At this point, I was experimenting a bit with BufferedImage, but creating such a huge BufferedImage raises memory exceptions even when the heap grows. Now I thought about splitting the image into several images / regions, and when I finished in a certain region, write it to disk and create a new region / BufferedImage and continue drawing. I'm interested in other people's thoughts on how they can handle this. I was out of Java for a while, so any specific examples are welcome.

+6
source share
2 answers

I am contributing to a new / small open source project that can be very well suited to your needs.

Glimpse Project It aims to help build 2D data visualization in Java, with particular emphasis on processing large datasets and simplifying real-time interactivity to easily explore data.

Glimpse head map

It uses OpenGL to use hardware features on modern GPUs such as texture memory and shaders to achieve the above goals. Therefore, if you use Java2D, this will not work for you. However, Glimpse panels can be placed side by side with other Swing components, making it easy to get into your existing Swing GUI. The only thing you need is a decent graphics card.

The image is an example of a large data matrix, the coloring of which is dynamically adjusted using the color bar on the right (matrix data is stored in the graphics processor texture, and dynamic repainting is performed using a custom shader). The source for this example is HeatMapExample.java . There are many other examples that provide starting points for working with other Glimpse functions.

You can find out more at glimpse.metsci.com . On the first page there is an embedded video, and examples of Java WebStart . Source posted on GitHub .

+3
source

if you just want to generate an image on disk, then look at pngj - it can generate large png images without any problems, it writes lines of pixels to the disk as they are available. The api is a bit png-specific, but it's not too complicated (this can help read a bit of background in png format before using it).

+1
source

Source: https://habr.com/ru/post/914843/


All Articles