Change color rgba Javascript

萝らか妹 提交于 2019-12-24 19:08:30

问题


Here is my JS code :

 UTIF._imgLoaded = function(e)
            {
                var page = UTIF.decode(e.target.response)[0], rgba = UTIF.toRGBA8(page), w=page.width, h=page.height;


                var string = rgba.join();
                console.log("rgba : ", rgba);

                var ind = UTIF._xhrs.indexOf(e.target), img = UTIF._imgs[ind];
                UTIF._xhrs.splice(ind,1);  UTIF._imgs.splice(ind,1);
                var cnv = document.createElement("canvas");  cnv.width=w;  cnv.height=h;
                var ctx = cnv.getContext("2d"), imgd = ctx.createImageData(w,h);
                for(var i=0; i<rgba.length; i++) imgd.data[i]=rgba[i];       ctx.putImageData(imgd,0,0);
                var attr = ["style","class","id"];
                for(var i=0; i<attr.length; i++) cnv.setAttribute(attr[i], img.getAttribute(attr[i]));
                img.parentNode.replaceChild(cnv,img);

                document.getElementById("myText").innerHTML = string;
            }

I get 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!

来源:https://stackoverflow.com/questions/47737503/change-color-rgba-javascript

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