将UIImage转换为NSData并在Swift中转换回UIImage? [英] Convert UIImage to NSData and convert back to UIImage in Swift?

查看:177
本文介绍了将UIImage转换为NSData并在Swift中转换回UIImage?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 UIImage 保存到 NSData ,然后阅读 NSData 返回Swift中的新 UIImage 。要将 UIImage 转换为 NSData 我正在使用以下代码:

I'm trying to save a UIImage to NSData and then read the NSData back to a new UIImage in Swift. To convert the UIImage to NSData I'm using the following code:

let imageData: NSData = UIImagePNGRepresentation(myImage)

如何将 imageData (即 NSData )转换回新的 UIImage

How do I convert imageData (i.e., NSData) back to a new UIImage?

推荐答案

UIImage(数据:imageData,比例:1.0)假设图像的比例为1.

UIImage(data:imageData,scale:1.0) presuming the image's scale is 1.

这篇关于将UIImage转换为NSData并在Swift中转换回UIImage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆