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 › Load images on-the-fly
Page Index Toggle Pages: 1
Load images on-the-fly (Read 359 times)
Load images on-the-fly
Feb 18th, 2009, 1:28pm
 
Hia,

Been playing with Processing for about 2 hours. What a fantastic thing..! Love it.

I'm trying to adapt the Examples > Topics > Animation > Sequential example. What I want it to do is monitor the files in the data directory (which are all named 01.jpg, 02.jpg and so on....) if/when a new file is added into the data directory I want the program to realise this and add that to the PImage object that is being looped.

I can't seem to figure out how to dynamically add (or remove) items from a PImage object. How would be a good way of going about this?

Hope this is clear.

Cheers,
Joe

Re: Load images on-the-fly
Reply #1 - Feb 18th, 2009, 2:21pm
 
http://www.processing.org/reference/PImage.html

You should find anything you need there... this is the reference, when you encounter a problem in Processing, before posting on the forum go there and have a look at images functions and all the related things. After a few minutes you should be able to load and display images.

Have a good day,
Odin
Re: Load images on-the-fly
Reply #2 - Feb 18th, 2009, 2:30pm
 
I've been going through the reference pages for some time, but I haven't managed to figure out how to do what I want.

My code is like this;

int numFrames = 11; //starting number of frames
int frame = 0;
PImage[] images = new PImage[numFrames];
   
void setup()
{
 size(600, 400);
 frameRate(5);
 loadimages(numFrames);
}


void loadimages(int frames)
{  
   for(int i=0; i<frames; i++) {
   String imageName = nf(i, 2) + ".JPG";
   images[i] = loadImage(imageName);
}



So I end up with this PImage object with 11 images in it.

I want to re-run loadimages(), but with 12 frames, or 13, or 14- but of course I get the out of bounds error message, because it is already set to 11. How do I redefine images[] so it has more elements?

I do apologise if this is in the reference, but I can't seem to find it it - causing me to think "maybe this is impossible, in this way"...

Thanks for your patience.

Joe

Re: Load images on-the-fly
Reply #3 - Feb 18th, 2009, 4:05pm
 
I think append() is what you need.
Note you don't need to reload all the images: to detect if a file exists, you can use the code:
File f = new File(imageName);
if (f.exists()) {
// load image and append to array
}
Re: Load images on-the-fly
Reply #4 - Feb 19th, 2009, 6:23pm
 
Yes! That has sorted it, thanks.

I did try to use append, where I ran into troubles was getting it to actually run. The mistake I made was with syntax I think; I didn't realise that the line

PImage[] images_updated = append(images_original, loadImage("03.JPG");

actually needed to be written like this;

PImage[] images_updated = (PImage[]) append(images_original, loadImage("03.JPG");

It is in the docs, I just missed it.

Anyway, many thanks for your help, the f.exists bit looks v useful too.

Best,
Joe

Page Index Toggle Pages: 1