将HEX String转换为UIImage

时间:2015-09-18 15:07:01

标签: ios swift nsdata

我有一些请求会返回一个JSON字符串作为响应。

我使用Alamofire框架,并在我解析JSON响应的函数中:

if let img = jsonData["my_data"]["img"].string{
   printl(img)
}

之后,我得到了描述

img = "\xffd8ffe000104a46494600010100000100010000ffdb0043000302020302020303030304030304050805050404050a070706080c0a0c0c0b0a0b0b0d0e12100d0e110e0b0b1016101113141515150c0f171816141812141514ffdb00430103040405040509050509140d0b0d1414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414ffc000110801e0035503012200021101031101ffc4001f0000010501010101010100000000000000000102030405060708090a0bffc400b5100002010303020403050504040000017d01020300041105122131410613516107227114328191a1082342b1c11552d1f02433627282090a161718191a25262728292a3435363738393a434445464748494a535455565758595a636465666768696a737475767778797a838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae1e2e3e4e5e6e7e8e9eaf1f2f3f4f5f6f7f8f9faffc4001f0100030101010101010101010000000000000102030405060708090a0bffc400b51100020102040403040705040400010277000102031104052131061241510761711322328108144291a1b1c109233352f0156272d10a162434e125f11718191a262728292a35363738393a43444546474"

我需要将此字符串转换为UIImage。我尝试使用以下代码执行此操作:

if let img = jsonData["status_order"]["img"].string {
    let myData = img.dataUsingEncoding(NSUTF8StringEncoding)
    // println(myData)
    let base64String = myData!.base64EncodedStringWithOptions(.allZeros)
    // println(base64String)
    let decodedData = NSData(base64EncodedString: base64String, options: NSDataBase64DecodingOptions(rawValue: 0))
    var decodedimage = UIImage(data: decodedData!)
    println(decodedimage)
    my_pic.image = decodeimage // I get nil
}

但之后我收到了一些错误:

  

2015-09-18 18:57:14.363 taxi-admin [1520:3e03]错误:无法得到   来自DB的接收器数据!

     

2015-09-18 18:57:16.822 taxi-admin [1520:4e03]错误:   ForceShrinkPersistentStore_NoLock -delete-我们没有BLOB或   TEXT列类型。相反,我们有5个。

0 个答案:

没有答案