Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Out of memory with BufferedImage

Reply
Thread Tools

Out of memory with BufferedImage

 
 
iamfractal@hotmail.com
Guest
Posts: n/a
 
      05-17-2004
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
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      05-17-2004
On 17 May 2004 15:45:55 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) 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.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
 
 
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      05-18-2004
(E-Mail Removed) wrote:
> 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
 
Reply With Quote
 
ak
Guest
Posts: n/a
 
      05-18-2004
> 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


 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      05-19-2004
On Tue, 18 May 2004 12:30:25 +0200, Thomas Weidenfeller
<(E-Mail Removed)> wrote or quoted :

>
>Read about AffineTransform in the API documentation.


for an intro, see http://mindprod.com/jgloss/affinetransform.html


--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Alex Hunsley
Guest
Posts: n/a
 
      05-21-2004
(E-Mail Removed) wrote:

> 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

 
Reply With Quote
 
perry
Guest
Posts: n/a
 
      05-24-2004
>
> 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

Roedy Green wrote:
> On 17 May 2004 15:45:55 -0700, (E-Mail Removed) wrote or quoted
> :


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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Native memory backed BufferedImage with NIO Roland Richter Java 4 10-22-2004 11:48 AM
Potential memory leak using BufferedImage and ImageIO in a servlet? Richard Corfield Java 0 03-04-2004 10:52 AM
Read PPM images as BufferedImage hz010c1877 Java 1 08-14-2003 08:32 PM
Copying BufferedImage Eel Java 2 07-10-2003 10:15 PM
DirectByteBuffer and BufferedImage for image acquisition Peter Szymanski Java 0 07-09-2003 12:29 PM



Advertisments