Transparent pixels using HTML5 canvas and getImageData?

Viewed 10073

In my application I need to get some images, process them, and save for later use. So I'm drawing them to a temporary canvas, then getting with getImageData function. But in output transparency is lost...

Here is my code:

var tempCanvas = document.createElement('canvas');
var tempContext = tempCanvas.getContext('2d');

tempContext.drawImage(image, 0, 0);
var imageData = tempContext.getImageData(0, 0, image.width, image.height);

My image has some transparent pixels but after this there are no transparent pixels in imageData how can I solve this issue?

Is there any way to convert Html Image to ImageData, so I can process it and then draw to canvas?

1 Answers
Related