Convert a screen capture into a UIImage UIImagePNGRepresentation

202 Views Asked by At

Below I convert a screen capture into a NSData UIImagePNGRepresentation.

But how do I correct the below code and convert a screen capture into a UIImagePNGRepresentation but ensure it's using a UIImage format and not 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)!
0

There are 0 best solutions below