【问题标题】:How to replace image pixel in Webos Palm js如何在 Webos Palm js 中替换图像像素
【发布时间】:2011-11-09 09:48:52
【问题描述】:

我想用 webos 中的其他颜色替换图像像素颜色。所以任何人都可以建议我如何做到这一点。 谢谢

【问题讨论】:

  • 使用 PDK 进行图像处理可能会更成功

标签: javascript image-processing webos palm-pre


【解决方案1】:

这可以通过使用 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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 2019-01-25
    相关资源
    最近更新 更多