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
Roedy Green - 17 May 2004 23:55 GMT
On 17 May 2004 15:45:55 -0700, iamfractal@hotmail.com wrote or quoted
>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.

Signature
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
perry - 24 May 2004 19:46 GMT
> 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
> On 17 May 2004 15:45:55 -0700, iamfractal@hotmail.com wrote or quoted
> see http://mindprod.com/jgloss/repaint.html for more details.
Thomas Weidenfeller - 18 May 2004 11:30 GMT
> Hi, folks!
>
[quoted text clipped - 10 lines]
> but after a couple of magnifications, the BufferedImage throws an
> OutOfMemory exception.
Read about AffineTransform in the API documentation.
/Thomas
Roedy Green - 19 May 2004 01:04 GMT
>Read about AffineTransform in the API documentation.
for an intro, see http://mindprod.com/jgloss/affinetransform.html

Signature
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
ak - 18 May 2004 20:15 GMT
> 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.
--
http://uio.dev.java.net
http://reader.imagero.com
Alex Hunsley - 21 May 2004 14:08 GMT
> Hi, folks!
>
[quoted text clipped - 10 lines]
> 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