2011-09-02 23 views

回答

0

這可以通過使用HTML5畫布API來完成。創建一個與圖像大小相同的畫布,然後將圖像繪製到畫布上。獲取圖像數據,並操縱離開!

var canvas = document.getElementById(canvasID); 
var context = canvas.getContext('2d'); 
var image = context.getImageData(0,0,canvas.width,canvas.height); 

image現在是一個imageData對象,其中包含一個數組data,其中包含圖像的所有像素。 假設您想要刪除第六列和第三行像素處的綠色分量。

var index = (5*image.width+2)*4; 
//six columns of pixels, plus two for the third row. 
//Multiply by four, because there are four channels. 
image.data[index+1] = 0; //Plus one, because we want the second component. 

一旦您的像素操作完成,將圖像數據加載回畫布。

context.putImageData(image);