将屏幕截图转换为UIImage UIImagePNGRepresentation

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

但是,如何纠正下面的代码,并将屏幕捕获转换成UIImagePNGRepresentation但确保它使用UIImage格式,而不是NSData

 // 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)!