Manipulate RGBA Javascript

风格不统一 提交于 2019-12-11 16:48:33

问题


In Javascript i have a Uint8Array() RGBA of image, here is console.log of this :

Here is image with rgba array as a string in HTML:

Is that possible to manipulate this array, to ex. change colors? Thanks for help!


回答1:


Here's a JS algorithm of plotting a pixel to this kind of array:

function changeColor(x, y, c)
{
   colorArray[(x * 4) + (y * (imageWidth * 4))] = c.r;
   colorArray[(x * 4) + (y * (imageWidth * 4)) + 1] = c.g;
   colorArray[(x * 4) + (y * (imageWidth * 4)) + 2] = c.b;
   colorArray[(x * 4) + (y * (imageWidth * 4)) + 3] = c.a;
}

where x and y are the coordinates of the pixel you want to change, imageWidth being the width of the image this array produces, c being the colour you want to change the pixel to, and colorArray is the array itself.



来源:https://stackoverflow.com/questions/47737257/manipulate-rgba-javascript

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