ImageData of an externally loaded Image?

Posted by sri on Stack Overflow See other posts from Stack Overflow or by sri
Published on 2010-04-22T07:35:33Z Indexed on 2010/04/22 9:13 UTC
Read the original article Hit count: 156

Filed under:
|

I load an external image and draw it on the Canvas element like so:

var canvas = document.getElementById('canvas1');
var context = canvas.getContext('2d');
var image = new Image();
image.onload = function(evt) { context.drawImage(evt.target, 0, 0); }
image.src = "test.jpg";

But I want to get the ImageData. So after calling context.drawImage, I do this:

var imagedata = canvas.getImageData();
manipulate(imagedata); // modifies imagedata.data
context.putImageData(imagedata, 0, 0);

Is that the only way to get the imageData of an externally loaded image? Drawing the image on canvas & then getting the imagedata seems awfully slow. Am I missing something?

Thanks!

© Stack Overflow or respective owner

Related posts about html5

Related posts about canvas