【发布时间】:2016-08-21 17:45:50
【问题描述】:
我目前正在使用以下方法将用户选择的UIImage 转换为 base64 字符串,但是当我使用以下方法将其转换回图像时,我可以获得NSData,但我可以不要将其转换为UIImage。有什么想法吗?我已经尝试对UIImage 使用 PNG 和 JPEG 方法,但如果添加了任何细节,它们都不起作用。
谢谢,
雅各布
编码代码:
var base64 = UIImagePNGRepresentation(self.profileView.image!))!.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.Encoding64CharacterLineLength)
解码代码:
let decodedData = NSData(base64EncodedString: String(user?.photoURL), options: NSDataBase64DecodingOptions.IgnoreUnknownCharacters)
let decodedimage = UIImage(data: decodedData!) //this decoded image is nil
【问题讨论】:
-
user?.photoURL是什么? -
您想将
NSData转换为UIImage?对吗? -
我会看
String(user?.photoURL),因为它可能包含一些“可选(...)”句法噪音... -
@MidhunMP 它来自 Firebase:这就是我获取当前用户的 base64 字符串的方式,其中包含他们的个人资料图片
-
@Rob 好的,会的
标签: ios swift string null uiimage