Loading...
Logo
Processing Forum
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:

  1. PImage img;
  2. PGraphics pg;
  3. boolean loaded = false;
  4.  
  5. void setup(){
  6. size(600,320);
  7. background(255);
  8. img = requestImage("data/trame.jpg");
  9. }
  10.  
  11. void initMask(){
  12. println("img loded");
  13. println("img.width: "+img.width+" img.height: "+img.height);
  14. pg = createGraphics(img.width, img.height, JAVA2D);
  15. println("pg.width: "+pg.width+" pg.height: "+pg.height);
  16. }
  17.  
  18. void draw(){
  19. background(150);
  20. if(img.width>1){
  21. if(!loaded){
  22. initMask();
  23. loaded=true;
  24. }
  25.  
  26. updatePg();
  27.  
  28. img.mask(pg); // apply PGraphics as PImage.mask()
  29. image(img,0,0);
  30.  
  31. image(pg,300,0);
  32.  
  33. fill(0);
  34. text("PImage with PGraphics mask", 5, 315);
  35. text("PGraphics", 305, 315);
  36. }
  37. }
  38.  
  39. void updatePg() {
  40. pg.beginDraw();
  41. pg.background(0);
  42. pg.noStroke();
  43. pg.fill(255);
  44. pg.ellipse(pg.width/2, pg.height/2, 200+cos(radians(frameCount))*100, 200+cos(radians(frameCount))*100);
  45. pg.endDraw();
  46. }
Any idea welcome.

Thanks.
http://makio.free.fr/

Replies(3)

try to uncomment this line ;)
Copy code
  1. image(pg,300,0);
As i thought, it changes nothing, i render the PGraphics on the left so that one can see it move.
Wish it would have been this simple, thanks anyway.

http://makio.free.fr/
I didn't check your linked example, only looked into the code. (And there was a problem with the PGrapics overlapping the masked image when you have a bigger source-image). Didn't realize it was a processsing.js-skript.

You actual problem seems to be an issue with processing.js there was a thread with a similar problem here.