Why is my CGImage 3 x the size of the UIImage

后端 未结 1 869
伪装坚强ぢ
伪装坚强ぢ 2021-01-24 17:16

I have a function that takes a UIImage and a colour and uses it to return a UIImage in just that colour.

As part of the function the UIImage is converted to a CGImage bu

相关标签:
1条回答
  • 2021-01-24 17:47

    It's because UIImage has a scale property. This mediates between pixels and points. So, for example, a UIImage created from a 180x180 pixel image, but with a scale of 3, is automatically treated as having size 60x60 points. It will report its size as 60x60, and will also look good on a 3x resolution screen where 3 pixels correspond to 1 point. And, as you rightly guess, the @3x suffix, or the corresponding location in the asset catalog, tells the system to give the UIImage a scale of 3 as it forms it.

    But a CGImage does not have such a property; it's just a bitmap, the actual pixels of the image. So a CGImage formed from a UIImage created from 180x180 pixel image is 180x180 points as well.

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