Out of memory with BufferedImage

Discussion in 'Java' started by iamfractal@hotmail.com, May 17, 2004.

  1. Guest

    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
     
    , May 17, 2004
    #1
    1. Advertising

  2. Roedy Green Guest

    On 17 May 2004 15:45:55 -0700, 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.
     
    Roedy Green, May 17, 2004
    #2
    1. Advertising

  3. 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
     
    Thomas Weidenfeller, May 18, 2004
    #3
  4. ak Guest

    > 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
     
    ak, May 18, 2004
    #4
  5. Roedy Green Guest

    Roedy Green, May 19, 2004
    #5
  6. Alex Hunsley Guest

    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
     
    Alex Hunsley, May 21, 2004
    #6
  7. perry Guest

    >
    > 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, wrote or quoted
    > :


    >
    > see http://mindprod.com/jgloss/repaint.html for more details.
    >
     
    perry, May 24, 2004
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Szymanski
    Replies:
    0
    Views:
    863
    Peter Szymanski
    Jul 9, 2003
  2. Eel

    Copying BufferedImage

    Eel, Jul 9, 2003, in forum: Java
    Replies:
    2
    Views:
    6,976
  3. hz010c1877

    Read PPM images as BufferedImage

    hz010c1877, Aug 14, 2003, in forum: Java
    Replies:
    1
    Views:
    6,911
    John C. Bollinger
    Aug 14, 2003
  4. Richard Corfield
    Replies:
    0
    Views:
    3,528
    Richard Corfield
    Mar 4, 2004
  5. Roland Richter
    Replies:
    4
    Views:
    6,191
    Roland Richter
    Oct 22, 2004
Loading...

Share This Page