I'd like to use a PGraphics as a mask on a PImage via PImage.mask(PGraphics).
It works fine in Processing (except for PImage with png with alpha, bug...) but there seems to be a problem as you can see HERE: there is no mask at all on the PImage
Code:
- PImage img;
- PGraphics pg;
- boolean loaded = false;
- void setup(){
- size(600,320);
- background(255);
- img = requestImage("data/trame.jpg")
; - }
- void initMask(){
- println("img loded");
- println("img.width: "+img.width+" img.height: "+img.height);
- pg = createGraphics(img.width, img.height, JAVA2D);
- println("pg.width: "+pg.width+" pg.height: "+pg.height);
- }
- void draw(){
- background(150);
- if(img.width>1){
- if(!loaded){
- initMask();
- loaded=true;
- }
- updatePg();
- img.mask(pg); // apply PGraphics as PImage.mask()
- image(img,0,0);
- image(pg,300,0);
- fill(0);
- text("PImage with PGraphics mask", 5, 315);
- text("PGraphics", 305, 315);
- }
- }
- void updatePg() {
- pg.beginDraw();
- pg.background(0);
- pg.noStroke();
- pg.fill(255);
- pg.ellipse(pg.width/2, pg.height/2, 200+cos(radians(frameCount))*1
00, 200+cos(radians(frameCount))*1 00); - pg.endDraw();
- }
Any idea welcome.
Thanks.
http://makio.free.fr/
1