如何调用本地图像文件并显示到imageviewcontroller中 [英] How to call the local image file and display into the imageviewcontroller

查看:68
本文介绍了如何调用本地图像文件并显示到imageviewcontroller中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个应用程序,该应用程序创建了本地存储的付款文件,而该应用程序未被删除.

I create the one application in that create the locally store the file in payment while the application not be deleted.

我已经完成:下载文件并将其存储在本地(应用程序文档"文件夹).

This I have done: I download the file and store into locally (applications document folder).

现在我遇到了麻烦: 在下载映像之后,然后我将其提取到本地,并且该映像将不会显示.在NSLog中,生成了以下URL,但我无法显示图像.

Now I am having trouble with this: While the after the image is downloaded then I fetch into locally and that image will not display. In NSLog following url is generated and i can't display the image.

/Users/username/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/F233ED88-1546-4FB0-BE93-0E0FB8C8C3D6/Documents/NationalMedalofArts-150x150.jpg

/Users/username/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/F233ED88-1546-4FB0-BE93-0E0FB8C8C3D6/Documents/NationalMedalofArts-150x150.jpg

NSURL *imageURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@",
                   @"/Users/username/Library/Application Support/iPhone Simulator/5.0/Applications/F233ED88-1546-4FB0-BE93-0E0FB8C8C3D6/Documents/NationalMedalofArts-150x150.jpg"]];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
NSLog(@"%@",imageData);
UIImage *image = [UIImage imageWithData:imageData];
self.imgView.image = image;

当NSLog记录NSData时,显示为NULL

when the NSLog the NSData then it's NULL to display

推荐答案

这更好:

NSString *fileName = @"NationalMedalofArts-150x150.jpg";
NSString *path = [NSString stringWithFormat:@"%@/Documents/%@", NSHomeDirectory(), fileName];
self.imgView.image = [UIImage imageWithContentsOfFile:path];

这篇关于如何调用本地图像文件并显示到imageviewcontroller中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆