[英]I want to encode and decode a UIImage to and from a String for a value in AEXML in swift
//To encode I found the following example. //为了进行编码,我找到了以下示例。 I don't know if it works yet
我不知道是否可行
@IBAction func exitImageViewController(seque:UIStoryboardSegue){ @IBAction func exitImageViewController(seque:UIStoryboardSegue){
let imageController = seque.destination as! MyImageViewController
let myView = imageController.imageView
imageData = UIImagePNGRepresentation((myView?.image!)!)
imageString = imageData?.base64EncodedString()
// Is this swift code correct? //此快速代码正确吗?
//I cannot find an example of decoding String back to UIImage //我找不到将String解码回UIImage的示例
The code you posted looks fine. 您发布的代码看起来不错。 To encode back you can do this:
要回编码,您可以执行以下操作:
let data = Data(base64Encoded: imageString!)
let img = UIImage(data: data!)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.