IOS从文件夹中获取图像使用完整链接

时间:2015-11-30 13:49:41

标签: ios objective-c uiimageview nsurl nsdocumentdirectory

我已将一些图像保存到文档文件夹中,之后我使用完全链接来获取图像。

strImageName是指向图片的完整路径。

    +(UIImageView *)getImage:(NSString*)strImageName showImage:(UIImageView*)showImage{
    NSData *data = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:strImageName]];
    UIImage *image = [UIImage imageWithData:data];
    showImage.image = image;
    return showImage;
}

但是,它得到数据= nil。

当我登录时,它会显示:

Failed to read file, error Error Domain=NSCocoaErrorDomain Code=260 "The operation couldn’t be completed. (Cocoa error 260.)" UserInfo=0x8517ff0 {NSFilePath=/var/mobile/Containers/Data/Application/7EE5BEC1-0F60-461A-8B29-5F9B425ED1A6/Documents/emoji29.png, NSUnderlyingError=0x8517f70 "The operation couldn’t be completed. No such file or directory"}

我有一些研究方法,但它不适合我。

如何解决此问题。

1 个答案:

答案 0 :(得分:0)

NSString *filePath = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"image1" ofType:@"png"] isDirectory:NO];

UIImage *image = [UIImage imageWithContentsOfFile:filePath];

相关问题