Hello
I am at the start of creating a program that can draw an image then copy sections of that image (in irregular shapes e.g. triangle) and overlay them on the stage. To extract sections of the initial drawing I have followed the 'graphic image mask' example here (
http://processing.org/discourse/yabb2/YaBB.pl?num=1231933751/1) but although I am setting no background() on any of the off-screen buffers the program will not preserve the background transparency.
It also seems to make the graphics crispy when drawing them to the stage although I have used the smooth() function throughout.
I am guessing this is something to do with the conversion from PGraphics to PImage but don't think I can apply a mask to PGraphic?
Not sure if I'm doing something wrong or if there is a better way to approach this problem...
- PGraphics drawing, dMask;
- PImage maskedImage;
- int iW, iH;
- void setup() {
- size(400, 400);
- smooth();
- iW = width;
- iH = height;
- drawing = createGraphics(iW, iH, JAVA2D);
- dMask = createGraphics(iW, iH, JAVA2D);
- drawImage();
- drawMask();
- display();
- }
- void drawImage() {
- drawing.beginDraw();
- drawing.smooth();
- for(int y = 0; y < height; y+= int(height/30)) {
- for(int x = 0; x < width; x+= int(width/30)) {
- drawing.ellipse(x, y, 10, 10);
- }
- }
- drawing.endDraw();
- }
- void drawMask() {
- dMask.beginDraw();
- dMask.smooth();
- dMask.noStroke();
- dMask.fill(255);
- dMask.triangle(width/2, 30, width-30, height-30, 30, height-30);
- dMask.endDraw();
- maskedImage = drawing.get();
- maskedImage.mask(dMask);
- }
- void display() {
- image(maskedImage, 0, 0);
- image(maskedImage, 50, 0);
- }
1