We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi,
I was trying to process a PImage to change particular pixels to become transparent but I could not get it to work. For example this would only turn the pixels to black:
img.loadPixels();
for (int x = 0; x < img.width; x++) {
for (int y = 0; y < img.height; ++y) {
if (x < y)
img.set(x, y, color(0, 0));
}
}
img.updatePixels();
So I tried in a simpler sketch and realized that the 3 rectangles in this sample would have different fill, one transparent, one almost transparent and one black (not expected with alpha to 0):
size(500, 200);
fill(0, 0);
rect(100, 50, 100, 100);
fill(color(0, 1));
rect(200, 50, 100, 100);
fill(color(0, 0));
rect(300, 50, 100, 100);
Can someone explain why does the pixels turn black instead of being transparent?
Thanks!
Answers
fill(0, 0)
&fill(color(0, 0))
is b/c any value within the [0 & 255] range is interpreted as opaque grey scale by both fill() & stroke()! @-)color(0, 0)
yields exactly 0. So it becomesfill(0)
.fill(color(0, 0), 0)
becomes the same asfill(0, 0)
! :>GoToLoop, once more you save the day!
I had forgot to mention that I did not care preserving the original color so my final version is a little bit simplified but I am sure it will be useful later.
Playing around with colors and alpha channels always seemed easy before but that case was tricky and proved that I should go back to study!
Thanks very much!