Solved

Image : "Out Of Memory" problem

Posted on 2002-04-29
3
194 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Android studio getdrawable(int) is deprecated 4 121
couple of eclipse 5 46
configure dependency in POM for new database 3 34
ejb message driven bean mdb creation steps 2 24
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

830 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