0

Here is my JS function :

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

I get a Uint8Array() RGBA of image, here is console.log of this : enter image description here

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

I try to change rgba of image by changeColor() function. I get in console.log error = "Color is not defined ". Thanks for help!

bafix2203
  • 541
  • 7
  • 25
  • `changeColor` function has 3 arguments, and you're passing none on call. that may be error. – Aleksandar Varicak Dec 10 '17 at 12:28
  • When you get a console error you also get the line number that the error occurred on. That line number would have directed you to the line with ` var c = new Color(r, g, b, a);` The error is telling you that there is no object in the current scope named `Color` and thus can not create it. – Blindman67 Dec 10 '17 at 18:31

0 Answers0