?
Solved

Image : "Out Of Memory" problem

Posted on 2002-04-29
3
Medium Priority
?
197 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

771 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