来自 uiwebview 中 sqlite db 和 html 的图像

Posted

技术标签:

【中文标题】来自 uiwebview 中 sqlite db 和 html 的图像【英文标题】:image from sqlite db and html in uiwebview 【发布时间】:2012-03-20 09:06:40 【问题描述】:

如果有人遇到同样的问题,请帮忙... 我有 sqlite db,在 NSData 中有图像。我需要在 uiwebview 中插入图像,但是……图像不显示……

NSString *html = [NSString stringWithFormat:
                   @"<html> <head>"
                   @"<style> body  font-family:Verdana;font-size:13px;</style>"
                   @"</head>"
                   @"<img src=\"%@\" />"
                   @"<br/>%@"
                   @"</body> </html>", datePicture,strDescription]] ;

然后我将它插入 UIWebview:

[descripWebView loadHTMLString:html baseURL:nil];

【问题讨论】:

NSDate 中的图片???你是说 NSData 吗? 【参考方案1】:

如果您的datePictureUIImage 类型,您可以将图像编码为base64 并将其直接嵌入到您的HTML 中。

NSString *html = [NSString stringWithFormat:
                   @"<html> <head>"
                   @"<style> body  font-family:Verdana;font-size:13px;</style>"
                   @"</head>"
                   @"<img src=\"data:Image/jpeg;base64,%@\" />"
                   @"<br/>%@"
                   @"</body> </html>", 
       [QSStrings encodeBase64WithData:UIImageJPEGRepresentation((datePicture, 1.0)],
       strDescription];

请注意,我使用的是 QSStrings 进行编码,可以在 QSUtilities on github 中找到

【讨论】:

以上是关于来自 uiwebview 中 sqlite db 和 html 的图像的主要内容,如果未能解决你的问题,请参考以下文章

来自sqlite的Android中的Textview显示

如何在QTableView Qt C ++中将sqlite db数据显示为多列视图?

如何访问 Android 模拟器中的本地文件夹以检索 SQLite db?

当 iPhone 应用程序在向表中插入数据时或期间退出时,如何回滚 SQLite DB?

带有预加载 sqlite3 数据库的 iOS 单元测试

来自 SQLiteOpenHelper 的 VACUUM sqlite 数据库