aspose file tools*
The moose likes Performance and the fly likes Showing Image in JFrame with g.drawImage() - increasing memory usage by switching image Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Showing Image in JFrame with g.drawImage() - increasing memory usage by switching image" Watch "Showing Image in JFrame with g.drawImage() - increasing memory usage by switching image" New topic
Author

Showing Image in JFrame with g.drawImage() - increasing memory usage by switching image

Pascal Jay
Greenhorn

Joined: Jan 08, 2011
Posts: 2
Hi guys,
I'm now to this forum and also a java beginner.

I've a problem with the image viewer I build. If I change the picture which will be showed (via drawImage(). repaint()) my memory usage increases everytime. So when I just switched through 20 pictures the memory usage of program ist near 250mb. The JFrame contains only a JPanel (in this Panel ist the ImagePanel on which the picture ist drawn) and 2 Buttons to switch through the pictures.

here's the code to draw the image on the ImagePanel (which extends JPanel) [ImagePanel class]:



After clicking on the "next image"-button I call this method from [class which rendering the gui and holds the ImagePanel (ip) object]:


Does someone have a idea how to hold the memory usage low?
Thanks for any answer !

best regards,
Pascal Jay Jonasson
Pascal Jay
Greenhorn

Joined: Jan 08, 2011
Posts: 2
I got a solution from another forum, thanks to KrokoDiehl from java-forum.org.
The solution ist to use a BufferedImage with Image.IO instead of an Image with ImageIcon.

In sourcecode:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Showing Image in JFrame with g.drawImage() - increasing memory usage by switching image