在ios中的imageView中显示路径中的图像

时间:2016-08-31 11:42:29

标签: ios objective-c xcode uiimageview uiimage

我有图像路径,我想在uiimageview中显示它,

  

/用户/ WTS-新建/库/开发商/ CoreSimulator /设备/ F43C 26D2-DCFF-4764-AAF0-F6CC7BCDCF5D /数据/钴ntainers /数据/方面的应用中/ 8E49D340-7CAC- 4031-85BF-9E5C26A1E3 7A /文档/小米ario.png

如何显示图像?

2 个答案:

答案 0 :(得分:2)

尝试使用以下代码:

从图片名称获取图片路径:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *imageFilePath;
NSError *err;

imageFilePath = [documentsDirectory stringByAppendingPathComponent:@"Small-m‌​ario.png"];

使用imageWithContentsOfFile方法设置图片:

YourImageView.image = [UIImage imageWithContentsOfFile: imageFilePath]; 

答案 1 :(得分:1)

To display image from complete file path on device

NSString *path = @"<your file path>;
NSURL *url = [NSURL fileURLWithPath:path];
NSData *data = [NSData dataWithContentsOfURL:url];
imageView.image = [UIImage imageWithData:data];

*The key is using fileURLWithPath instead of URLWithString when converting to NSURL