将 base64 数据解码为图像 [英] Decode a base64 data to image
本文介绍了将 base64 数据解码为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此代码不再适用于 Swift 3.
This code doesn't working with Swift 3 anymore.
imageData = NSData(base64EncodedString: mediaFile, options: NSDataBase64DecodingOptions.fromRaw(0)!)
这个也是.
imageData = NSData(base64EncodedString: mediaFile, options: .allZeros)
推荐答案
直接使用 Swift 3 native Data
而不是使用 NSData
.
Instead of using NSData
use directly Swift 3 native Data
.
if let decodedData = Data(base64Encoded: mediaFile, options: .ignoreUnknownCharacters) {
let image = UIImage(data: decodedData)
}
这篇关于将 base64 数据解码为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文