Solved

Image : "Out Of Memory" problem

Posted on 2002-04-29
3
191 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
Comment Utility
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
Comment Utility
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
Comment Utility
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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 basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now