【问题标题】:How to get Pixel from image in WebOS?如何从 WebOS 中的图像中获取像素?
【发布时间】:2012-06-07 22:47:26
【问题描述】:

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

【问题讨论】:

  • 我只是在猜测,但也许我们有 PDK(?)它将允许您使用比 javascript 更广泛用于图像处理的本机 C、C++。但是,如果我们可以用 Mojo 做些什么,我也很想知道答案:)
  • 谢谢@nacho4d,我没有想到pdk,原生的开发方式。我会尝试使用它。我有一些脚本来获取像素并对其进行操作。一旦我得到解决方案,我一定会发布它。

标签: image pixel webos


【解决方案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). 

【讨论】:

    猜你喜欢
    • 2011-11-09
    • 1970-01-01
    • 2013-07-11
    • 2019-07-27
    • 2013-07-21
    • 1970-01-01
    • 1970-01-01
    • 2020-03-19
    • 2011-05-08
    相关资源
    最近更新 更多