【问题标题】:Convert BLOB image from NSData to NSString so it can be displayed in HTML UIWebView将 BLOB 图像从 NSData 转换为 NSString,以便可以在 HTML UIWebView 中显示
【发布时间】:2011-09-30 13:53:15
【问题描述】:

所以我成功地从数据库中检索了我的 BLOB 图像并将其设置为 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

我遇到的问题是将我的 NSData 转换为 NSString,这样我就可以将其放入我的 UIWebView 的 loadHTMLString....我不能使用 UIImage,必须是 UIWebView。

谢谢! 格雷格

【问题讨论】:

    标签: uiwebview nsstring blob nsdata


    【解决方案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]; 
    

    我能够通过将文件写入 png 来找出我的解决方案。 webDirectory 是您选择的目录

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多