jQuery in Action, 3rd edition
The moose likes Performance and the fly likes Drawing Image Doubles Memory Consumption Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Drawing Image Doubles Memory Consumption" Watch "Drawing Image Doubles Memory Consumption" New topic

Drawing Image Doubles Memory Consumption

Mohammad Farhat
Ranch Hand

Joined: Nov 17, 2005
Posts: 51
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 img.imagerep.biRaster.data). 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

Joined: Feb 01, 2007
Posts: 77
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 ]
I agree. Here's the link: http://aspose.com/file-tools
subject: Drawing Image Doubles Memory Consumption
jQuery in Action, 3rd edition