How to change the color of a base64-encoded png image JQuery?
0 Answer(s)      3 years and 9 months ago
Posted in : JavaScript Questions

I am going to change the colors of the pixels of a png image(which is in base64 format). This is my source code:

var myImg = new Image();
myImg.src = <...>; //"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAABQklEQVR4nO3bC27CMBAFQ";
myImg.onload = function() {
    var canvas = document.createElement("canvas");
    var ctx = canvas.getContext("2d");
    var imgd = ctx.getImageData(0, 0, myImg.width, myImg.height);

    for (i = 0; i <; i += 4) {[i]   = 255;[i+1] = 0;[i+2] = 255;
    ctx.putImageData(imgd, 0, 0);

the problem is that when I check the value of[i] (before changing the color), it is zero for every i. the original image is shown, but the color does not change. Do you know why?

View Answers

Related Tutorials/Questions & Answers: