0
我正在使用Caman JS來修改圖像。我只想修改像素子集的Alpha通道。但是當我應用濾鏡時,它會修改圖像中的所有像素。有關如何修改像素子集的任何建議。我需要創建一個插件而不是過濾器嗎?使用CamanJS操作圖像的一部分
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 =函數(){ VAR偏移,X,Y; offset = { x:170, y:150 }; x = 50; y = 50; image.maskAlpha(x,y,255); return 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
});
});
});