UIWebview - 加载PNG图像 - 出错

时间:2012-05-31 08:47:49

标签: ios

我正在尝试在UIWebview中加载图像(png)。但是我得到了以下错误 “”ImageIO:PNGinvalid文字/长度设置“

我将从网络服务获得“png”。我将它存储在以下路径中。 “Users / XXX / Library / Application Support / iPhone Simulator / 4.3.2 / Applications / E4DE3097-EA84-492F-A2A7-5882202F3B00 / Documents / attachement.png”

当我从路径中读取文件时,我收到了错误。我使用以下代码

  NSBundle *bundle = [NSBundle mainBundle]; 


  NSString *path = [bundle bundlePath];
    NSURL *baseURL = [NSURL fileURLWithPath:path];

    NSString *commentHtml = [NSString stringWithFormat:@"<img src=\"%@\"/>", documentEntity.path];
    NSString *html3 = [NSString stringWithFormat:@"<html><head/><body><div><b>COMMENTS:</b></div>%@</body></html>", commentHtml];
    [self.documentView loadHTMLString:html3 baseURL:baseURL];

请帮帮我。

感谢 吉里贾

1 个答案:

答案 0 :(得分:1)

如果您已将图像保存在文档文件夹中,为什么要从MainBundle获取。 从文档目录中获取图像将是:

    NSString *aDocumentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString *aFilePath = [NSString stringWithFormat:@"%@/attachement.png", aDocumentsDirectory];
    UIImage *anImage = [UIImage imageWithContentsOfFile:aFilePath];