将BLOB图像从NSData转换为NSString,以便可以在HTML UIWebView中显示 [英] Convert BLOB image from NSData to NSString so it can be displayed in HTML UIWebView
问题描述
所以我成功地从数据库中检索了我的BLOB图像,并将其设置为NSData * content ..
So I successfully retrieved my BLOB image from the database and set it to NSData *content..
content = [[NSData alloc]
initWithBytes:sqlite3_column_blob(query, 16)
length:sqlite3_column_bytes(query, 16)];
我想做的是将这些内容放入NSString中,因为我想将此字符串传递给javascript并显示图像.我不确定这是否可能,但是我已经阅读了下面的链接,您可以在base64的css/html中显示图像. http://mark.koli.ch/2009/07/howto-include-binary-image-data-in-cascading-style-sheets-css.html
What I am trying to do is to get this content into a NSString, because I would like to then pass this string to javascript and display the image. I am not exactly sure if this is even possible, but i have read on the link below that you can display images in css/html in base64. http://mark.koli.ch/2009/07/howto-include-binary-image-data-in-cascading-style-sheets-css.html
我遇到的问题是将NSData转换为NSString,这样我就可以将其放入我的 UIWebView的loadHTMLString ....我不能使用UIImage,必须是UIWebView.
The issue I am having is converting my NSData to an NSString so I can then put it into my UIWebView's loadHTMLString....I cannot use a UIImage, must be a UIWebView.
谢谢! 格雷格
推荐答案
content = [[NSData alloc] initWithBytes:sqlite3_column_blob(query, 16) length:sqlite3_column_bytes(query, 16)]; NSString *path = [webDirectory stringByAppendingPathComponent:@"image.png"]; [content writeToFile:path atomically:NO]; [content release];
我能够通过将文件写成png来找出解决方案.其中webDirectory是您选择的目录
I was able to figure out my solution by writing the file out to a png. Where webDirectory is your directory of choice
这篇关于将BLOB图像从NSData转换为NSString,以便可以在HTML UIWebView中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!