Solved

Image : "Out Of Memory" problem

Posted on 2002-04-29
3
193 Views
Last Modified: 2010-03-31
I'm creating a Java image that representing data scanned by a camera.
I put this image in a JScrollPane. The image can be very big (500x80,000 pixels).
My worst problem is that I get (when the image is very big or when the screen resolution is very hight) an "Out Of Memory" Exception. Otherwise, when it works, it takes very long time for the image to be drawn.
The image is "very" simple : less than 10 colors and I use mostly "g.fillRect(...)" see my pseudo code below.

Is there any better ways to draw this image using less memory and less draw time ?

Thank you.

NB : when I use the "-Xmx200m" option to run the application I solve the memory problem but i'm looking for a better way. Also the draw time problem still exist.


private Image img_=null;

public void paintComponent(Graphics gr){
     super.paintComponent(gr);
     if(img_ == null){
          Dimension d = getSize();
          img_ = createImage(d.width, d.height);
          Graphics g = img_.getGraphics();

          (...)
          g.setColor(...);
          g.fillRect(...);
          g.drawLine(...);
          g.drawString(...);
          Graphics2D g2d = (Graphics2D) g;
          g2d.setPaint(...);
          g2d.setStroke(...);
          g2d.draw(new Line2D.Double(...));
          g.drawRect(...);
     }

     gr.drawImage(img_, 0, 0, this);

}
0
Comment
Question by:mynameis_luca
3 Comments
 
LVL 3

Expert Comment

by:shyamkumarreddy
ID: 6979952
Luca,
How did you build your application.
For long images memory required is more and possible of out of memory.
But wonderful abt the smaller images.

Shyam
0
 
LVL 9

Expert Comment

by:Venci75
ID: 7992585
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
PAQ'd and pts removed

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Venci75
EE Cleanup Volunteer
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 8048443
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question