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

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

    Swift 3

    The Swift 3 solution (based on Dima's answer) with UIView extension should be like this:

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

提交回复
热议问题