ImageData of an image downloaded externally?

I load the external image and draw it on the Canvas element as follows:

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 ImageData. So after calling context.drawImage , I do this:

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

Is this the only way to get imageData of an image downloaded externally? Drawing an image on canvas and then getting imagedata seems awfully slow. Did I miss something?

Thank!

+3
source share
2 answers

ImageData, , , , , , - , , , .

, , ImageData , - ( ) .

+3

Ajax, , .

0

Source: https://habr.com/ru/post/1742238/


All Articles