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 › Change the pixels become transparent
Page Index Toggle Pages: 1
Change the pixels become transparent (Read 921 times)
Change the pixels become transparent
Apr 9th, 2010, 7:54am
 
I want to know how can I make the pixel of the black img becomes trasparent when my mousemoved() to that pixel.

When the mousemoved() to somewhere, that area's pixels of the black.img will become transparent, so that I can see another image masked by the black img.
Re: Change the pixels become transparent
Reply #1 - Apr 9th, 2010, 7:56am
 
Maybe try:
pixels[pos] &= 0x00FFFFFF;
Re: Change the pixels become transparent
Reply #2 - Apr 9th, 2010, 8:50am
 
i know that i need to set the color become transparent, but can u show me more hints on how to make it work?
Re: Change the pixels become transparent
Reply #3 - Apr 10th, 2010, 2:40am
 
Code:
PImage imgC, imgBW;
// Size of transparency area around the mouse
int HALF_HOLE_SIZE = 7;
// Change to true to avoid restoring opacity (ie. paint with background image)
boolean bPersist = false;

void setup()
{
size(300, 400);
// Load a color image
imgC = loadImage("D:/_PhiLhoSoft/images/me.jpg");
// Load a black & white image (the same)
imgBW = loadImage("D:/_PhiLhoSoft/images/me_BW.jpg");
// Indicate we need transparency on this image
imgBW.format = ARGB;
noStroke();
smooth();
background(255);
}

void draw()
{
// Draw the color image
image(imgC, 0, 0);
if (!bPersist)
{
// Restore opacity on previous position
ChangePixels(pmouseX, pmouseY, true);
}
// Make pixels transparent around the mouse position
ChangePixels(mouseX, mouseY, false);
// Draw the altered B&W image
image(imgBW, 0, 0);
}

void ChangePixels(int x, int y, boolean bMakeOpaque)
{
// Primitive, lazy tests, should be improved (
if (x <= HALF_HOLE_SIZE || x >= imgBW.width - HALF_HOLE_SIZE) return;
if (y <= HALF_HOLE_SIZE || y >= imgBW.height - HALF_HOLE_SIZE) return;
// Get the pixel data
imgBW.loadPixels();
// Walk a square around the given position
for (int i = x - HALF_HOLE_SIZE; i <= x + HALF_HOLE_SIZE; i++)
{
for (int j = y - HALF_HOLE_SIZE; j <= y + HALF_HOLE_SIZE; j++)
{
if (bMakeOpaque)
{
imgBW.pixels[i + j * imgBW.width] |= 0xFF000000;
}
else // Make transparent
{
imgBW.pixels[i + j * imgBW.width] &= 0x00FFFFFF;
}
}
}
// Update the modified pixels
imgBW.updatePixels();
}
Re: Change the pixels become transparent
Reply #4 - Apr 10th, 2010, 5:22am
 
thanks a lot!!
Page Index Toggle Pages: 1