简体   繁体   中英

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.

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.

一瞥头图

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 .

if you just want to generate the image on disk, then look at pngj - it can generate big png images with no problems because it writes lines of pixels to disk as they are available. the api is a little png-specific, but it's not too complex (it might help to read a little background on the png image format before using it).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM