Out of memory with BufferedImage

I

iamfractal

Hi, folks!

I have a BufferedImage onto which I'm drawing simple lines and
polygons, but I want to allow the user to magnify the final graphic
and allow, "Zooming-in," on a choice line or polygon.

To cater for this magnification, I'd like the graphic to be placed in
a JScrollPane, so that, as the user zooms, the graphic can be dragged
about.

My problem is that, as I magnify, I must double the size of the
BufferedImage each time and draw the lines and polygons twice as big;
but after a couple of magnifications, the BufferedImage throws an
OutOfMemory exception.

Is there a simple way to create allocate memory for only a particaly
part of a BufferedImage, rather than for the whole thing?

(I want neither to use the Image.getScaledInstance() to zoom-in
(because of pixellation), nor to increase heap-size to allow for
monster BufferedImages.)

Thanks,

..ed

www.EdmundKirwan.com
 
R

Roedy Green

Is there a simple way to create allocate memory for only a particaly
part of a BufferedImage, rather than for the whole thing?

You only required in your paint or paintComponent method to draw the
part inside the clipBounds

You can draw just that part of the model from scratch each time paint
is called. Then you only have the vector storage, which does not get
bigger when you magnify.

If you want to get very clever, you can predraw tiles, and cache them,
only redrawing tiles as needed. If you want to get very fancy, you do
your redrawing in the background, preemptively guessing which tiles
you will need next.


see http://mindprod.com/jgloss/repaint.html for more details.
 
T

Thomas Weidenfeller

Hi, folks!

I have a BufferedImage onto which I'm drawing simple lines and
polygons, but I want to allow the user to magnify the final graphic
and allow, "Zooming-in," on a choice line or polygon.

To cater for this magnification, I'd like the graphic to be placed in
a JScrollPane, so that, as the user zooms, the graphic can be dragged
about.

My problem is that, as I magnify, I must double the size of the
BufferedImage each time and draw the lines and polygons twice as big;
but after a couple of magnifications, the BufferedImage throws an
OutOfMemory exception.

Read about AffineTransform in the API documentation.

/Thomas
 
A

ak

I have a BufferedImage onto which I'm drawing simple lines and
polygons, but I want to allow the user to magnify the final graphic
and allow, "Zooming-in," on a choice line or polygon.
You don't need BufferedImage for this, so don't use it!
You should just redraw all your lines/poligons every time.
 
A

Alex Hunsley

Hi, folks!

I have a BufferedImage onto which I'm drawing simple lines and
polygons, but I want to allow the user to magnify the final graphic
and allow, "Zooming-in," on a choice line or polygon.

To cater for this magnification, I'd like the graphic to be placed in
a JScrollPane, so that, as the user zooms, the graphic can be dragged
about.

My problem is that, as I magnify, I must double the size of the
BufferedImage each time and draw the lines and polygons twice as big;
but after a couple of magnifications, the BufferedImage throws an
OutOfMemory exception.

If you must DIY: what Roedy said.
Otherwise, why not use Piccolo? http://www.cs.umd.edu/hcil/piccolo/
The hard graft has already been done for you!

alex
 
P

perry

If you want to get very clever, you can predraw tiles, and cache them,
only redrawing tiles as needed. If you want to get very fancy, you do
your redrawing in the background, preemptively guessing which tiles
you will need next.

thats like, pretty cool

- perry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top