我想用 webos 中的其他颜色替换图像像素颜色。那么任何人都可以建议我如何做到这一点。 谢谢
最佳答案
这可以通过使用 HTML5 canvas API 来完成。创建一个与图像大小相同的 Canvas ,然后将图像绘制到 Canvas 中。获取图像数据,然后进行操作!
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.
完成像素操作后,将图像数据加载回 Canvas 。
context.putImageData(image);
关于javascript - 如何在 Webos Palm js 中替换图像像素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7287789/