1
    var img, imageData,width,height; 
    var c = canvasEle.getContext("2d");
    width = canvasEle.width;
    height = canvasEle.height;

    img = document.getElementById("id");
    c.drawImage(img,0,0);
    imageData = c.createImageData(width, height);

After I draw the image onto the context, then create an imageData array, the values of the array are all 0.

I have been struggling with this for hours and couldn't find any solution. The image is shown on the canvas after I draw it, but the imageData of the context says all the pixels are white. This doesn't make any sense to me.

4

1 回答 1

3

createImageData您一起为空图像创建新图像数据。请用于getImageData从现有画布中获取图像数据

于 2013-10-08T12:56:40.220 回答