[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Image : "Out Of Memory" problem

Posted on 2002-04-29
3
Medium Priority
?
198 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

649 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