We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Loading images in draw
Page Index Toggle Pages: 1
Loading images in draw? (Read 881 times)
Loading images in draw?
May 5th, 2009, 12:24pm
 
I'm working on a project right now where I scrape images from google in Max/MSP/Jitter and then load them into a sketch in processing. What I am doing is downloading the images to a folder and then sending the file name to processing over a UDP port to processing to load the image while the sketch is running. I figure that this would require loading images in draw? My main problem is that I can't figure out how to load images into processing while a sketch is running. Considering the files are downloaded in realtime I can't specify the file names before loading the sketch. In addition, I am planning on there to be eventually be hundreds of images, so saving each file as a different name (ex. google1, google2, google3,) and loading them into an array doesnt seem to be quite feasible either. <-- EDIT this doesnt even need to be addressed at this point... if I can get one image loaded into processing while the sketch is running I'm sure I could figure it all out from there.

sorry if I'm not incredibly clear.
Re: Loading images in draw?
Reply #1 - May 5th, 2009, 12:47pm
 
Quote:
I am planning on there to be eventually be hundreds of images, so it seems that saving each file as a different name (ex. google1, google2, google3,) so loading them into an array isnt in that way doesnt seem to be quite feasible either.


why not? you could name them inserting in their name an incremental number. if you don't like the idea you could make image array or arraylist; in this case you could simply call each image just with an index.

also, depending on the logic of you program, you could also think to just "forget" old images and concentrate just on the newest one:
Code:
imagename = getImageName(); // the function youre using to get the image name
image(imagename, x, y);

this way you each draw cycle puts a new image at x,y.
Re: Loading images in draw?
Reply #2 - May 5th, 2009, 2:00pm
 
You probably cannot load all the images before starting draw(), both for time spent and for memory constraints.
As naus3a said, you can load images on demand, freeing memory if you no longer need them.
I usually advice against loading images in draw(), because it is slow and the way people do it, they would load an image 60 times per second!
But of course you can make that loading conditional, on a given time frame, etc.
The problem is that loadImage() will indeed stop the drawing until the image is loaded. Fortunately, Processing authors thought of that, and made requestImage(), allowing asynchronous loading.
Re: Loading images in draw?
Reply #3 - May 5th, 2009, 2:03pm
 
Sorry, I just re-read my post and saw how sloppy and poorly-worded it was.

My main problem is that I won't have the images downloaded before the sketch runs. What I'm looking for is a way to load the images into processing while the sketch is running. I can't load the images into the sketch before running it because they haven't been downloaded yet.

a = loadImage(message); //message = name of the file scraped from google, sent over the UDP from Max

Is that more clear? Thanks so much for your help! I'm completely new to p5.
Re: Loading images in draw?
Reply #4 - May 5th, 2009, 2:09pm
 
PhiLho  wrote on May 5th, 2009, 2:00pm:
You probably cannot load all the images before starting draw(), both for time spent and for memory constraints.
As naus3a said, you can load images on demand, freeing memory if you no longer need them.
I usually advice against loading images in draw(), because it is slow and the way people do it, they would load an image 60 times per second!
But of course you can make that loading conditional, on a given time frame, etc.
The problem is that loadImage() will indeed stop the drawing until the image is loaded. Fortunately, Processing authors thought of that, and made , allowing asynchronous loading.


Aha! It looks like this may be what I need. Thank you, I'm looking into it now.
Page Index Toggle Pages: 1