How to change the color of a base64-encoded png image JQuery?

How to change the color of a base64-encoded png image JQuery?

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");
    ctx.drawImage(myImg,0,0);
    var imgd = ctx.getImageData(0, 0, myImg.width, myImg.height);

    for (i = 0; i <imgd.data.length; i += 4) {
        imgd.data[i]   = 255;
        imgd.data[i+1] = 0;
        imgd.data[i+2] = 255;
    }
    ctx.putImageData(imgd, 0, 0);
    $("#Cell").append(myImg);
}

the problem is that when I check the value of imgd.data[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

Ads









Related Tutorials/Questions & Answers:
How to change the color of a base64-encoded png image JQuery?
how to change color of titlebar in java
Advertisements
How can I change UIButton title color?
how to change div background color in javascript
how to re size image proportionately using java for different images like jpeg, png, gif.
How to change table row color when click on Hyper Link in jsp?
How to change color of opened Bootstrap drop down toggle?
how to create menubar and the below background color/image in java swing
How to change image size before adding to mysql using jsp
dynamic image change javascript
change color according to the database value
MKMapView Change Red Pin Color
Get image color
change navbar dropdown color in bootstrap
change color of back ground using switch
Change Color and Font of text
Get the color values as a matrix of color image
change the name of the image after uploading the image
How to change the face, change the face
How to design a changing color of the chameleon, changing color of the chameleon, color of the chameleon
How to change background, change background
to change the styleclass color of <apex:outputlabel > onclick button function in javascript
PNG images become black colored during create image
Color Effect On Image
Storing the Color Image pixel values into 2d array
which values we have to use for compressing any color image
Change JPanel background color from mouse entered/exit event
How to design a color tray
changing Chunk Color
How to Changing Toolbar Color using iPhone Application ?
PNG and JPG

Ads