如何在Webos Palm JS中替换图像像素 [英] How to replace image pixel in Webos Palm js

查看:46
本文介绍了如何在Webos Palm JS中替换图像像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

这可以通过使用HTML5 canvas API来完成.创建一个图像大小的画布,然后将图像绘制到画布中.获取图像数据,然后操纵!

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 现在是一个 imageData 对象,它包含一个数组 data ,该数组包含图像的所有像素.假设您要删除第六列和第三行像素中的绿色分量.

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);

这篇关于如何在Webos Palm JS中替换图像像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆