• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Processing large images in Swing

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?



 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic