Creating retina screenshot programmatically resulting in non retina image

只谈情不闲聊 提交于 2019-12-05 21:48:50

I don't see anything wrong in your code. Apart from image.size, have you tried logging image.scale? Is it 1 or 2? If it's 2, it is actually a retina image.

UIImage.scale represents the scale of the image. So an image with UIImage.size being 320×480 and UIImage.scale being 2 has an actual size of 640×960. From Apple's doc:

If you multiply the logical size of the image (stored in the size property) by the value in this property, you get the dimensions of the image in pixels.

It's the same idea as when you load an image into a UIImage with the @2x modifier. For example:

a.png (100×80)      => size=100×80 scale=1
b@2x.png (200×160)  => size=100×80 scale=2
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!