Canvas drawing and Retina display: doable?

前端 未结 6 1396
北荒
北荒 2020-12-15 06:13

Working with phoneGap implementing drawing with Canvas. The catch we\'ve run into is that canvas expects specific pixel dimensions. This is fine except that the iPhone 4\'s

6条回答
  •  别那么骄傲
    2020-12-15 07:08

    I couldn't find anywhere else on the internet suggesting this so I figured it out. If you have a full screen canvas and you want it to be the actual amount of pixels that the device has, just remove this line from your HTML:

    
    

    Don't set the viewport at all. Then you just do:

    canvas.width = innerWidth
    canvas.height = innerHeight
    canvas.style.width = innerWidth+'px'
    canvas.style.height = innerHeight+'px'
    

    That will use the full screen resolution of the device. A pixel will always be a pixel. You don't need to scale. And getImageData() will give the same values that you see.

提交回复
热议问题