Resizing Large Resolution Images Producing 1000x1000 Pixels Size when Size is set to 500x500 Pixels

前端 未结 1 823
予麋鹿
予麋鹿 2021-01-29 12:07

Im using the following extension method to resize an image.When it comes to large resolution images the output size remains 1000x1000 pixels even when I set the output size to 5

相关标签:
1条回答
  • 2021-01-29 12:50

    The problem is that you are not taking into account the scale of the image you're creating.

    You have a Retina screen. When you call lockFocus and draw into the resulting graphics context, the graphics context has double-resolution. Thus, a size of 500x500 results in an underlying bitmap of 1000x1000. That doesn't matter for purposes of display; to the extent that it does matter, it's a good thing.

    But when you proceed to save the image data to disk, you throw away the knowledge that this is a double-resolution image, and you simply save the bitmap — which is 1000x1000.

    You should look at Apple's documentation on how to deal with high-resolution images, e.g. https://developer.apple.com/library/content/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/APIs/APIs.html

    0 讨论(0)
提交回复
热议问题