How to capture UIView to UIImage without loss of quality on retina display

前端 未结 17 1503
时光取名叫无心
时光取名叫无心 2020-11-22 00:42

My code works fine for normal devices but creates blurry images on retina devices.

Does anybody know a solution for my issue?

+ (UIImage *) imageWith         


        
17条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 01:15

    UIGraphicsImageRenderer is a relatively new API, introduced in iOS 10. You construct a UIGraphicsImageRenderer by specifying a point size. The image method takes a closure argument and returns a bitmap that results from executing the passed closure. In this case, the result is the original image scaled down to draw within the specified bounds.

    https://nshipster.com/image-resizing/

    So be sure the size you are passing into UIGraphicsImageRenderer is points, not pixels.

    If your images are larger than you are expecting, you need to divide your size by the scale factor.

提交回复
热议问题