Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Drawing Image Doubles Memory Consumption  RSS feed

Mohammad Farhat
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,
i am using an applet to display images (i would of placed this question under applet, but it is memory consumption)
So the issue is that i have this image, which is stored inside an Image instance. When i am trying to render on a canvas, the memory consumption would double, and then, i end up having two different instances of the pixels of the image (saw that using a memory profiler - one of them is img.source.pixels, the other is This is critical since some images come in 20MB pixel size, so now i am ending up with 40MB per image (double size)
the code i am using to draw the image is using double buffering relying on an Graphics object (offg) which references the image through the
offg = offImage.getGraphics();
and then drawing using the drawImage to draw the image instance (parent.imageDataArray[imgNo].getCurrentImage())
(int) x[imgNo],
(int) y[imgNo],
(int) w[imgNo],
(int) h[imgNo],

Even without double buffering, i still get the double memory consumption. Is the drawImage making another copy of the image in memory, causing therefore the duplication of memory usage. And is there a way to draw the image while avoiding this?
Thanks a lot guys
Harjit Singh
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are the images files static which you are loading from the File System ? If yes please try

Image image;
public void init() {
// Load image
image = getImage(getDocumentBase(), "image.gif");
public void paint(Graphics g) {
// Draw image
} g.drawImage(image, 0, 0, this);
[ February 15, 2007: Message edited by: Harjit Singh ]
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!