如何在WebOS中从图像中获取Pixel?

时间:2011-06-02 12:01:29

标签: image pixel webos

我有图像,我必须读取该图像的所有像素值。我必须在webOS中这样做。有什么方法可以做到这一点?

1 个答案:

答案 0 :(得分:1)

这个问题有点类似于另一个问题,我回答here。基本上,您需要将该图像绘制到画布上,使用getImageData获取像素数组,然后只访问数组中的像素。

总之,此示例在(5,2)处找到像素的绿色分量:

var canvas = document.getElementById(canvasID);
var context = canvas.getContext('2d');
var image = context.getImageData(0,0,canvas.width,canvas.height);
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 (R,G,B,A).