我正在尝试使用以下代码将base 64编码的字符串转换为UIImage
:
let decodedData = NSData(base64EncodedString: base64String!, options: NSDataBase64DecodingOptions(rawValue: 0) )
print(decodedData) //I get data here (It is not nil)
var decodedimage = UIImage(data: decodedData!) //return nil
decodedData
看起来不错,为什么在转换为nil
时会得到UIImage
? 最佳答案
尝试不传递任何选项,我也建议对选项使用unwrap:
if let string = base64String {
let decodedData = NSData(base64EncodedString: base64String!, options: [])
if let data = decodedData {
var decodedimage = UIImage(data: data)
} else {
print("error with decodedData")
}
} else {
print("error with base64String")
}
关于ios - 快速将字符串Base64转换为UIImage,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39943388/