我正在使用 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.doWhatever = function() { var offset, x, y; 偏移量 = { x: 170, y: 150 }; x = 50; y = 50; image.maskAlpha(x, y, 255); 返回图像.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
});
});
});