简体   繁体   中英

How I can mask PNG image with another PNG image with KineticJS?

So, I have a picture, and I need to overlay it with another picture by PNG mask (black/transparent image). How I can to do this with KineticJS?

sorry for my bad english

Create custom Kinetic.Shape :

var image = new Kinetic.Shape({
    draggable: true,
    x : 100,
    y : 100,
    sceneFunc : function(ctx) {
      ctx.drawImage(mask, 0, 0);
      ctx.setAttr('globalCompositeOperation', 'source-in');
      ctx.drawImage(img, 0, 0);
    },
    hitFunc : function(ctx) {
      ctx.rect(0,0,img.width, img.height);
      ctx.fillStrokeShape(this);
    }
  });

http://jsbin.com/bagix/1/edit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM