Any help cutting/cropping out part of a PGraphics image, leaving behind a transparent rectangle?
I tried the code below, but it just adds a transparent rectangle on top (no visual change to the underlying image). I did change the fill to (255, 100) to verify the coordinates and dimensions, it added a light white semi-transparent rectangle on top of what’s (still visible) underneath.
Thanks for the help Kevin. Sorry to leave out the constructor and display:
size(500, 500);
PGraphics img = createGraphics(500, 500);
img.beginDraw();
img.noStroke();
img.fill(255, 0);
img.rect(100, 100, 200, 200);
img.endDraw();
image(img, 0, 0);
I am having some luck writing to the pixels directly: java.util.Arrays.fill(img.pixels, 1000, 100000, color(255, 0));
You could also play with the blendMode() function. I think blendMode(REPLACE) might be what you’re looking for, but I haven’t tried it out. More info can be found in the reference.
setting blendMode(REPLACE); and then setting your stroke/fill color to transparent color(0,0,0,0); will let you draw transparency with lines, rects, anything you want really.
It works well. Just don’t forget to send your blendMode back to the default blendMode(BLEND); when you’re done.