将屏幕捕获转换为UIImage UIImagePNGRepresentation

时间:2017-07-17 20:53:34

标签: ios swift optimization uiimage uiimagepngrepresentation

下面我将屏幕截图转换为NSData UIImagePNGRepresentation

但是,如何更正以下代码并将屏幕截图转换为UIImagePNGRepresentation,但确保使用的是UIImage格式,而不是NSData < / p>

// Take snapshot of screen
var imageSnapshot: UIImage!
UIGraphicsBeginImageContextWithOptions(self.view.frame.size, false, 0)
self.view.drawViewHierarchyInRect(CGRect(x: 0, y: 0, width: self.view.bounds.width, height: self.view.bounds.height), afterScreenUpdates: false)
imageSnapshot = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

// Prepare image to PNG format
let imageShare: NSData
imageShare = UIImagePNGRepresentation(imageSnapshot)!

0 个答案:

没有答案