开发者

How to get Pixel from image in WebOS?

Am havi开发者_如何学运维ng am image, i have to read all the pixel values of that image. And i have to do it in webOS. What are the ways to do that?


This question is somewhat similar to another one, which I answered here. Basically, you'll want to draw that image to a canvas, use getImageData to get the pixel array, and then just access the pixel within the array.

In summary, this example finds the green component of the pixel at (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). 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜