【问题标题】:image from sqlite db and html in uiwebview来自 uiwebview 中 sqlite db 和 html 的图像
【发布时间】: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 吗?

标签: html sql ios image


【解决方案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 中找到

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-19
    • 1970-01-01
    • 1970-01-01
    • 2013-04-20
    相关资源
    最近更新 更多