将image / jpeg从GET请求转换为UIImage

时间:2016-04-08 00:14:46

标签: ios swift http get uiimage

我有一些限制,无法使用本机序列化程序或Alamofire。我只对身体(编码图像)和Content-Type = image / jpeg做出回应。这段代码不起作用:

let responseString = response as! String
let data = NSData(bytes: responseString, length: responseString.characters.count)
let image = UIImage(data: data, scale: 1.0) // nil

1 个答案:

答案 0 :(得分:2)

您的回复本身就是NSData直接尝试

var image = UIImage(data: response, scale: 1.0)