下面我将屏幕截图转换为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)!