[whatwg] More random comments on the putImageData definition

Anne van Kesteren annevk at opera.com
Fri Jan 25 15:05:56 PST 2008

On Fri, 25 Jan 2008 23:57:56 +0100, Oliver Hunt <oliver at apple.com> wrote:
> Another thing that we need is some way to determine what the device  
> pixel->css pixel ratio is.  Currently there's isn't even a real way to  
> tell that it's 1:1 -- you would have do do a fillRect(width-1, height-1,  
> 1, 1),; then getImageData(width-1, height-1, 1, 1) and see if they  
> match.  Conceivably you could do this multiple times to estimate the  
> ratio, but it would be non-trivial.

You can determine this by checking the height and width attributes on the  
ImageData object. If you get a 2x2 region and ImageData.width and .height  
return 4 you know there's a factor two scaling happening between canvas  
pixels and device pixels. What the factor is between canvas pixels and CSS  
pixels isn't really relevant (and easy to determine).

Anne van Kesteren

More information about the whatwg mailing list