使用Camanjs在图像的一部分上操作



我正在使用Caman JS修改图像。我想仅修改像素子集的alpha通道。但是,当我应用过滤器时,它会修改图像中的所有像素。有关如何仅修改像素子集的任何建议。我需要创建插件而不是过滤器吗?

window.doWhatever=->
   offset={x:170,y:150}
   #for i in [0..10]
   #  for j in [0..10]
   #    x=j+offset.x
   #    y=i+offset.y
   #    image.maskAlpha(x,y,0)
   x=50
   y=50
   image.maskAlpha(x,y,255)
   image.render()
 Caman.Filter.register 'maskAlpha',(x,y,alphain)  ->
   this.process 'maskAlpha', ->
   pixel=this.getPixel(x,y)
   this.putPixel(x,y,{
   r:pixel.r,
   g:pixel.g,
   b:pixel.b,
   a:alphain})

或在JavaScript中
window.dowhate = function(){ var偏移,x,y; 偏移= { X:170, Y:150 }; x = 50; y = 50; image.maskalpha(x,y,255); 返回image.render(); };

 Caman.Filter.register('maskAlpha', function(x, y, alphain) {
   return this.process('maskAlpha', function() {
     var pixel;
     pixel = this.getPixel(x, y);
     return this.putPixel(x, y, {
       r: pixel.r,
       g: pixel.g,
       b: pixel.b,
       a: alphain
      });
   });
 });

由于webkit和其他浏览器实现的缺陷和其他浏览器实现的缺陷,如果将alpha设置为0。p> alpha的书面问题

相关内容

最新更新