Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Pascal Jay
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic