Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating and drawing huge (Buffered) images in Java

I'm working on an application which draws out a matrix - using Java 2D - which can become quite large, for example 30000 x 30000 pixels. At this moment I've experimented a bit with BufferedImage but creating such a huge BufferedImage causes out of memory exceptions, even when enlarging the heap. Now I was thinking splitting the image up into several images/regions, and when I'm done in a certain region write it to disk and create a new region/BufferedImage and continue drawing. I'm interested in thoughts of other people on how they would handle this. I've been away from Java for a while so any concrete examples are welcome.

like image 379
RBaarda Avatar asked May 03 '12 21:05

RBaarda


1 Answers

I contribute to a new/small open source project which may be quite well suited to your needs.

The project is Glimpse. Its intended to aid in construction of 2D data visualizations in Java with a focus on handling large data sets well and making it easy to provide real-time interactivity to allow easy exploration of data.

Glimpse Head Map

It utilizes OpenGL to take advantage of hardware features on modern GPUs like texture memory and shaders to achieve the above goals. So if you're set on using Java2D then this won't work for you. However, Glimpse panels can be placed side-by-side with other Swing components, so it's easy to drop into your existing Swing GUI. The only caveat it that you'll need a decent graphics card.

The image is an example of a large matrix of data whose coloring is being dynamically adjusted via the color scale on the right (the matrix data is stored in a GPU texture and the dynamic re-coloring is accomplished via a custom shader). The source for this example is HeatMapExample.java. There's lots of other examples like that which provide starting points for working with Glimpse's other features.

You can learn more at glimpse.metsci.com. There's an intro video on the front page, along with Java WebStart examples. The source is hosted on GitHub.

like image 116
ulmangt Avatar answered Oct 04 '22 13:10

ulmangt