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.
Page Index Toggle Pages: 1
masking images (Read 501 times)
masking images
Jan 12th, 2006, 8:10pm
 
Hi,

Is it possible to load an image into a layer and mask the image, so that it fits within a polygon shape - or even better: mask the image, so that it fits within the outline of another image ?

thanks,
am
Re: masking images
Reply #1 - Jan 12th, 2006, 9:18pm
 
You can load an image, then load another image to use as a mask for it, which may give you the result you're looking for. The mask image shoule be black and white, and I think white is solid, black is transparent, and everything in between works as expected.

Code:
PImage img;
PImage imgMask;

void setup()
{
size(400,400,P3D);
img=loadImage("MyImage.gif");
imgMask=loadImage("MyImageMask.gif");
img.mask(imgMask);
}


Or, if you're looking to do complex shapes at runtime, you coudl use the image as a texture on a polygon, and by setting the texture co-ordinates, only show ther parts of the image you want.

Code:
PImage img;

void setup()
{
size(400,400,P3D);
img=loadImage("MyImage.gif");
}

void draw()
{
background(0);
// ... other code ...
beginShape(POLYGON);
texture(img);
// only the 20 pixel border of the image not used
// (assuming it's 100x100) except a bit near the bottom..
// try it and see..
vertex(20,20,20,20); // x,y imageX, imageY
vertex(80,20,80,20);
vertex(80,80,80,80);
vertex(50,90,50,90);
vertex(20,80,20,80);
endShape();
}
Page Index Toggle Pages: 1