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









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
color change
How can I change UIButton title color?
how to change div background color in javascript
how to change background color in dojo tab container - Framework
how do you change the message box to a specific color
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 backgroundcolor and foreground color of JLabel in Java - Java Beginners
change player dress color
Get image color
Change the color of the selected tab
How to change image size before adding to mysql using jsp
MKMapView Change Red Pin Color
change color according to the database value
dynamic image change javascript
change navbar dropdown color in bootstrap
JavaScript change background color automatically
Convert Black & White Image to Color Image
To change the color of text hyperlinks midway
To change the color of text hyperlinks midway
To change the color of text hyperlinks midway
change color of back ground using switch
change one type of color in between more colors
Java Servlet Change Background Color
Change Color and Font of text
Get the color values as a matrix of color image
PHP GD Colorization of image
Change background color of text box - Java Beginners
Photoshop change a background image
PHP GD image negative Color
change the name of the image after uploading the image
PNG images become black colored during create image
How to design a changing color of the chameleon, changing color of the chameleon, color of the chameleon
How to change the face, change the face
Conversion from color to Gray Image - Java Beginners
to change the styleclass color of <apex:outputlabel > onclick button function in javascript
Color Effect On Image
Storing the Color Image pixel values into 2d array
UINavigationBar Color - iPhone example
How to change background, change background
servlet backgorund color change - JSP-Servlet
Photoshop eye color brown to blue
which values we have to use for compressing any color image
Change JPanel background color from mouse entered/exit event
UIWebView Background Color
How to design a color tray

Ads