在 iPhone 中将图像的 NSData 从数据库转换为 NSString [英] Convert NSData of Image from database to NSString in iPhone

查看:59
本文介绍了在 iPhone 中将图像的 NSData 从数据库转换为 NSString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将图像的 NSData 从数据库转换为 Iphone 中的 NSString

I am converting NSData of Image from database to NSString in Iphone

这是我的代码

imageData1 = [[NSData alloc] initWithBytes:sqlite3_column_blob(compiledStatement, 3) length: sqlite3_column_bytes(compiledStatement, 3)];           
NSString * Str1 = [NSString base64StringFromData: imageData1 length: [imageData1 length]];
NSData *data1=[NSData base64DataFromString:Str1];
NSString* newStr1 = [[NSString alloc] initWithData:data1 encoding:NSUTF8StringEncoding];

数据长度为6511,但newstr1为nil

the length of data is 6511 , but the newstr1 is nil

关于这个问题:我不能从数据库中的任意二进制数据中创建一个 UTF-8 编码的字符串——数据实际上需要是 UTF-8 编码的.我也完成了 base 64 编码和解码.我该如何解决这个问题.我只需要 NSString 的格式,将其作为 csv 文件的输入?

With reference to this question: I can't create a UTF-8 encoded string out of just any arbitrary binary data from the database - the data needs to actually be UTF-8 encoded. I have aslo done base 64 encoding and decoding. How can I solve this issue. I need it in the format of NSString only, to give it as input to a csv file?

推荐答案

我对字符编码没有足够的了解,但仅在输出中使用 Base 64 编码字符串 (Str1) 是否还不够?

I don't have ample knowledge of character encoding, but would it not be sufficient to just use the Base 64 encoded string (Str1) in your output?

我担心将 Str1 重新编码为 data1 会让您回到第 1 方格并撤消之前在该行中完成的任何 Base 64 编码.

I fear that re-encoding Str1 as data1 brings you right back to square 1 and undoes any Base 64 encoding done in the line earlier.

这篇关于在 iPhone 中将图像的 NSData 从数据库转换为 NSString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆