How do you simply obtain an array of pixel data from an image?

无人久伴 提交于 2019-12-01 03:11:41

This should be exactly what you need :

http://www.html5canvastutorials.com/advanced/html5-canvas-get-image-data-tutorial/

Below is how to access to a pixel RGBA details:

imageData = context.getImageData(imageX, imageY, imageWidth, imageHeight); // get the image array

//below is how to access to your pixel details 
red=imgData.data[0];
green=imgData.data[1];
blue=imgData.data[2];
alpha=imgData.data[3];

Edit: The answer to your edited question is :

document.getElementById("data").innerHTML=imgData.data.toString();

or you can use a loop to iterate over the array and print an element each time like below:

for(i=0 ; i< imgData.data.length ; i++){
    document.getElementById("data").innerHTML += imgData.data[i];
}

I hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!