0

我正在尝试在 UIWebview 中加载图像(png)。但我收到以下错误“”ImageIO:PNGinvalid literal/lengths set“

我将从网络服务中获取“png”。我将它存储在以下路径中。“用户/XXX/库/应用程序支持/iPhone 模拟器/4.3.2/Applications/E4DE3097-EA84-492F-A2A7-5882202F3B00/Documents/attachment.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];

请帮我。

谢谢 Girija

4

1 回答 1

1

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

    NSString *aDocumentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString *aFilePath = [NSString stringWithFormat:@"%@/attachement.png", aDocumentsDirectory];
    UIImage *anImage = [UIImage imageWithContentsOfFile:aFilePath];
于 2012-05-31T09:34:24.500 回答