这是我的 JS 函数:
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);
var c = new Color(r, g, b, a);
console.log(c);
function changeColor(x, y, c) {
rgba[(x * 4) + (y * (w * 4))] = c.r;
rgba[(x * 4) + (y * (w * 4)) + 1] = c.g;
rgba[(x * 4) + (y * (w * 4)) + 2] = c.b;
rgba[(x * 4) + (y * (w * 4)) + 3] = c.a;
console.log("Change :");
}
changeColor();
document.getElementById("myText").innerHTML = string;
}
我得到了一个 Uint8Array() RGBA 图像,这里是 console.log 这个:
我尝试按changeColor()
功能更改图像的 rgba。我进入 console.log 错误 =“颜色未定义”。感谢帮助!