How to replace image pixel in Webos Palm js

六月ゝ 毕业季﹏ 提交于 2019-12-13 00:46:32

问题


I want to replace image pixel color with other color in webos. so can any one suggest how i do this. Thanks


回答1:


This can be done by using the HTML5 canvas API. Create a canvas the size of the image, and then draw the image into the canvas. Get the image data, and manipulate away!

var canvas = document.getElementById(canvasID);
var context = canvas.getContext('2d');
var image = context.getImageData(0,0,canvas.width,canvas.height);

image is now an imageData object, which contains an array data, which contains all pixels of the image. Suppose you wanted to remove the green component at the pixel in the sixth column and the third row.

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. 

Once your pixel manipulation is done, load the image data back into the canvas.

context.putImageData(image);


来源:https://stackoverflow.com/questions/7287789/how-to-replace-image-pixel-in-webos-palm-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!