Convert BLOB image from NSData to NSString so it can be displayed in HTML UIWebView

旧街凉风 提交于 2019-12-25 06:44:59

问题


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)];

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

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.

Thanks! Greg


回答1:


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]; 

I was able to figure out my solution by writing the file out to a png. Where webDirectory is your directory of choice



来源:https://stackoverflow.com/questions/6613017/convert-blob-image-from-nsdata-to-nsstring-so-it-can-be-displayed-in-html-uiwebv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!