We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everyone,
I'm playing with video on processing and I'm trying to draw a mask and put a video on it. The thing is I keep getting a "mask() can only be used with an image that's the same size" error. The video I'm using is 640x360px. The weird part is that sometimes (about 1 in 10) the sketch runs and works ok!!
If anyone could give me hand here would be great.
Here's the code:
import processing.video.*;
Movie movie;
PImage mask01;
void setup() {
size(640,360);
movie = new Movie(this, "experiment_1.mp4");
movie.loop();
mask01 = createImage(width, height, ALPHA);
}
void draw() {
//draw the mask - 1/4 window width
mask01.loadPixels();
for (int x=0; x < width; x++) {
for (int y=0; y < height; y++) {
int loc = x + y * width;
if (x < width/4) {
mask01.pixels[loc] = color(255);
} else {
mask01.pixels[loc] = color(0);
}
}
}
mask01.updatePixels();
movie.mask(mask01);
image(movie,0,0);
}
void movieEvent(Movie movie) {
movie.read();
}
Answers
You have to apply the mask on a PImage, not on a PGraphics. Here is a simple example:
http://bazaar.launchpad.net/~philho/+junk/Processing/view/head:/_QuickExperiments/MaskImage/MaskImage.pde
I'm testing this with PGraphics but I'm getting the same mask() size error on the line movie.mask(mask01Shape);
Am I doing something wrong? :) Thanks.
If you reject an answer, you should indicate why. Have you tried? Have you a problem with the suggestion? Which one?
Sorry PhiLho. It doesn't work. It works when masking an image not a video (even though I believe it should). The way I got it to work was to code the masks and then actually save a .tga file and load it. That worked. Copying a PGraphic to a PImage didn't. Anyway, Processing seems to be very slow running several videos simultaneously.
Thanks for your time.