Loading Images

edited June 2014 in How To...

Ok so I am developing a sketch that requires loading in alot of images.

I have two type Gifs and pngs. I am getting a slow sketch at startup and sometimes an out of memory error. I know this is due to loading alot of images at start-up.

I just want to know if there is a java or processing method for loading and trashing images dynamically or loading them outside of setup() only when needed to be drawn??

Cheers in advance


  • edited June 2014
    • If you get outta memory errors, you gotta decide how many PImage objects need to be active in RAM at a given moment.
    • If you need to choose a PImage by name, you gotta use a HashMap<String, PImage> in order to store the active 1s.
    • Otherwise, an ArrayDeque as a Queue<PImage> is more adequate for displaying all of the active 1s at once in the canvas.
    • Set apart a function to pre-load and cache the files that are gonna be needed soon as a separate thread("").
  • so say I queue the Pimages, do I have to do that in setup or can I do it in its own class outside of setup?

  • BTW I will not need to display more than 2 of the loaded images at once... I just thought all loadimage() had to be in setup??

  • edited June 2014

    I just thought all loadImage() had to be in setup??

    If we got RAM, it's practical to load everything in setup()!

    ... 2 of the loaded images at once.

    It's always forward, or does it have rewind?
    If it's always forward, a Queue of loaded images is enough.
    Otherwise, you'd need 2 Deque instead!

  • look at page three of General share your work, my image loading prog may help. Can load many images, if available memory. will play all images in a buffer, stops at last buffer image until all are complete.

    regards, Algwat

Sign In or Register to comment.