You can sample pixel color data on a canvas image with getImageData(). If I layer a transparent canvas element over a background image or flash movie, can I sample a color from that via the canvas tag?
You can sample pixel color data on a canvas image with getImageData(). If I layer a transparent canvas element over a background image or flash movie, can I sample a color from that via the canvas tag?
Share Improve this question asked Mar 25, 2009 at 9:54 GeuisGeuis 42.3k57 gold badges163 silver badges223 bronze badges 1- This question is possibly relevant (and I'm trying to solve the same problem): stackoverflow./questions/2754865/… – Anderson Green Commented Jul 17, 2012 at 21:14
2 Answers
Reset to default 5Phil's right, you can't do it. Canvas, by design, only returns its own intrinsic pixel data, not any on-screen rendered content originating from other elements.
You could make a canvas element that covers the entire page and captures an image of the rendered screen.
If possible, that would be a cross-site-scripting security hole. You could iframe a target site (leveraging the users cookies/authentication/intranet to access it), then suck out the content from it pixel by pixel.
I think not. You would get the colour of the canvas at that point. I did find the method document.defaultview.getComputedStyle(element,pseudoElt)
, but on a 1 pixel div with no background-color, it returned 'transparent'.
So, unfortunately, this may be impossible at present. What is your higher-level aim? We may be able to e up with an alternative route.
"I had an idea earlier to copy image data into a javascript object. You could make a canvas element that covers the entire page and captures an image of the rendered screen. Once you have that data, you could do real-world cross browser testing, perhaps."
If you don't mind that it's a static image, there is a great website that does this for you: Browser Shots. It generates screenshots of your website running in a huge range of different browsers.