Convert a screen capture into a UIImage UIImagePNGRepresentation

僤鯓⒐⒋嵵緔 提交于 2019-12-12 04:16:27

问题


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

来源:https://stackoverflow.com/questions/45153494/convert-a-screen-capture-into-a-uiimage-uiimagepngrepresentation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!