Is it possible to use the ImageData object to retrieve x,y pixel locations on an html5 canvas that are ‘black’? I am fairly new to the canvas and am having a hard time figuring out if this is possible or how to implement it.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Indeed you can do that.
You will have to
getImageDataof the canvas context and loop through it in a block of 4s which represent the RGBA channels and then compare each channel separately.ImageData for multiple pixels is a bit tricky.
Imaging
var imgData = ctx.getImageData(0, 0, width, height);:Now
imgData.datais a big array which has the following format:Check demo for what you asked http://jsfiddle.net/GXrd5/