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

前端 未结 17 1762
时光取名叫无心
时光取名叫无心 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:09

    Swift 3.0 implementation

    extension UIView {
        func getSnapshotImage() -> UIImage {
            UIGraphicsBeginImageContextWithOptions(bounds.size, isOpaque, 0)
            drawHierarchy(in: bounds, afterScreenUpdates: false)
            let snapshotImage = UIGraphicsGetImageFromCurrentImageContext()!
            UIGraphicsEndImageContext()
            return snapshotImage
        }
    }
    

提交回复
热议问题