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 & HelpPrograms › Image mask() does not update each frame
Page Index Toggle Pages: 1
Image mask() does not update each frame (Read 590 times)
Image mask() does not update each frame
Aug 15th, 2008, 11:33am
 
hi,
I am trying to dynamically mask an image, but I find that the mask is applied just one time, and does not update after that. Even though I am changing the mask each time in the draw() function.

Can someone please tell me what I'm missing?

thanks,
arun


Code:

PImage img;
int[] imgMask;

void setup() {
size(320, 240);
img = loadImage("test.jpg");
imgMask = new int[320*240];
frameRate(24);
}

void draw() {
color band1;
color band2;
if (random(0,2) > 1.0) { //select white or black
band1 = color(0); //bands at random
band2 = color(255);
println("black-white"); //debug test to see if it does
} else { //print both black-white & white-black
band1 = color(255); //in the console ie. mask is
band2 = color(0); //being changed.
println("white-black");
}

for (int i=0; i < (320*240); i++) {
if (floor(i/width) % 5 == 0) { //every 5th row is
imgMask[i] = band1; //band1
} else { //others are
imgMask[i] = band2; //band 2
}
}
}


Re: Image mask() does not update each frame
Reply #1 - Aug 15th, 2008, 1:51pm
 
Each time you update the array, you need to call the mask() function.

However if you need to update the mask on each frame, it's probably more efficient to just manipulate the pixels[] array directly.
Re: Image mask() does not update each frame
Reply #2 - Aug 15th, 2008, 4:57pm
 
Sorry, I missed adding that code to the end of the sketch. I do have the following at the end of the draw function:

img.mask(imgMask);
image(img, 0, 0);

But it still does not work.

Re: Image mask() does not update each frame
Reply #3 - Aug 15th, 2008, 5:01pm
 
Are you using release 0144?
Re: Image mask() does not update each frame
Reply #4 - Aug 15th, 2008, 5:30pm
 
I'm using 0135. I tried 0144, but got errors about JDK not being found, all though I have JDK 1.6 installed on WinXP-Prof.

I'm downloading the 0144 with JDK version to see if that works.

In your script while launching processing, how are you checking for JDK being installed? Are you looking for a JAVA_HOME environment variable, or checking to see if javac exists?
Re: Image mask() does not update each frame
Reply #5 - Aug 15th, 2008, 6:13pm
 
Its working in 0144.

thanks,
arun
Page Index Toggle Pages: 1