• Post Reply Bookmark Topic Watch Topic
  • New Topic

Processing large images in Swing  RSS feed

 
Remi Passmoilesel
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone !

I am developing an application where a user can draw shapes on a canvas (a JPanel). On the canvas background are drawn multiple images that can form a (very) large image. The user can zoom in / out and move the image.

Until now I did not really try to optimize. Everything is loaded into memory (BufferedImage) and when the OutOfMemoryError come, the program crash. But now I want to do something a little better, I would like the user to use very large images and I do not really know what strategy is best.

Above all, despite much research I have not found any library made to handle this kind of problem, is there one?

Otherwise there is a strategy to manage this problem? A design pattern?

Should I write the image to disk, ensuring that the user changes the image and reflect the changes on the display?

Thank for your attention
 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

How large are your images? I would expect you to be able to draw shapes on a panel and store them in a form using a few kB. How are you handling the shapes? Do you have objects to represent the different shapes? What are you using for zooming?

I shall take the liberty of moving you to our GUIs forum.
 
Remi Passmoilesel
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply Ritchie

How large are your images?

Images aren't so big, about 0.5MP to 1MP but there are many. Now with -xmx 1GB I can handle around 25 MP.

How are you handling the shapes? Do you have objects to represent the different shapes ?

Shapes and images are specialized objects (tile, ellipse, square, line ...) stored in lists (layers) and painted in JPanel at each time repaint() is called. All paint is done with the standard Graphics2D API.

What are you using for zooming?

Graphics2D API. I use g2d.scale(sx, sy)

Shapes aren't the problem I think. They use few memory, the problem is with images. BufferedImage take lot of memory.
Maybe I can try to design a system with the whole image on disk (shapes and images assembled) and a special panel who read and paint only an interresting area.
But before try to do this I am looking for something easier, or at least documentation on this kind of system.


Do you know what is the most popular way to achieve this ?



 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!