I'm so sorry, but I've found out now that it's technically (or apparently) impossible
to recover an alpha attribute from a pixel after it was drawn to a
PGraphics surface.
No matter whether it's from main canvas or a separate off-screen buffer!
I'm still learning Processing/Java, and haven't realized how Processing manipulates colors w/ alpha attribute!
Even though you've missed your (school?) schedule, I'll explain the technical reason why:
Imagine you draw a red ellipse w/
fill(#FF0000). If you try to get a pixel within its area,
you'd expect to find a pixel color = #FF0000, right? Well, most of the time you'll get exactly that!
But now, draw another shape somewhere else, but this time w/
fill(#FF0000, 200),
that is, a red color w/ alpha = 200.
However, if you try to get a pixel color from there now, you won't get a #FF0000 or a 0xC8FF0000.
Instead, another pixel color, which corresponds visually to 0xC8FF0000, but has its alpha attribute reset to 255!
Interestingly, the bottom surface layer retains all of its color code, including its alpha attribute!
Only the other pixels drawn above it have their alpha reset to 0xFF!
And even their RGB attributes are altered if they weren't 100% opaque before!
As you can conclude as well, any alteration of the alpha attribute is lost, since it gets back to 0xFF once drawn!
Adieu any hope to use a slightly altered alpha to serve as a pixel detection mark for your shapes!
Nevertheless, I've still got another plan to use slightly altered RGB attributes as a masking mark.
Gonna make one as soon as I have more time!
Here's a post in which I've made a technique to crop an image w/ transparency outta main canvas:
http://forum.processing.org/topic/wanna-change-direction-with-keypressed
That's where I've drawn hope of this whole mess alpha mark idea!
See my debug program below to test this Processing's alpha color behavior for yourself:
final static short myAlpha = 251;
final static color bg = 0100;
PGraphics pg;
void setup() {
size(300, 200);
noLoop();
pg = createGraphics(width, height, P2D);
pg.beginDraw();
pg.smooth();
pg.rectMode(CENTER);
pg.endDraw();
}
void draw() {
pg.background(bg, myAlpha); // clears PGraphics w/ transparency color
pg.fill(#00FF00); // no alpha, intact color code
pg.rect(width >> 1, height >> 1, width >> 2, height >> 2);
pg.fill(#FFFF00, myAlpha); // transparency, color will be modified
pg.ellipse(width >> 1, height >> 2, width >> 2, height >> 1);
pg.fill(#00FFFF, myAlpha); // transparency, color will be modified
pg.ellipse(width >> 2, height >> 1, width >> 1, height >> 2);
background(pg); // clears canvas using PGraphics image
}
void mouseMoved() {
print( "mx: " + mouseX + "\tmy: " + mouseY );
//println( "\t" + checkAlphaMarkOnMouseBGPixel(get(), myAlpha) );
println( "\t" + checkAlphaMarkOnMouseBGPixel(g, myAlpha) );
//println( "\t" + checkAlphaMarkOnMouseBGPixel(pg, myAlpha) );
}
boolean checkAlphaMarkOnMouseBGPixel(PImage img, int alphaValue) {
loadPixels(); // dumps contents of PImage into pixels[]
color pix = img.pixels[ width*mouseY + mouseX ]; // gets pixel's color
print( "\n" + (width*mouseY + mouseX) + "\t");
// true if mouse is over a pixel w/ matching alpha:
print( hex(pix) );
return pix >>> 030 == alphaValue; // returns true if alpha code is found
}