How to render each pixel of a bitmap texture to each native physical pixel of the screen on macOS?

前端 未结 2 1886
旧时难觅i
旧时难觅i 2021-01-21 12:35

As modern macOS devices choose to use a scaled HiDPI resolution by default, bitmap images get blurred on screen. Is there a way to render a bitmap pixel by pixel to the true na

2条回答
  •  深忆病人
    2021-01-21 13:05

    If these are resource images, use asset catalogs to provide x2 and x3 resolution version of your images, icons, etc. Classes like NSImageView will automatically select the best version for the display resolution.

    If you just have some random image and you want it draw at the resolution of the display, get the backingScaleFactor of the view's window. If it's 2.0 then drawing a 200 x 200 pixel image into a 100 x 100 coordinate point rectangle will draw it at 1:1 native resolution. Similarly, if the scale factor is 3.0, a 300 x 300 pixel image will draw into a 100 x 100 coordinate point rectangle.

    Not surprisingly, Apple has an extensive guide on this subject: High Resolution Guidelines for OS X

提交回复
热议问题