1

I have image path and I want to display it in uiimageview,

/Users/WTS-New/Library/Developer/CoreSimulator/Devices/F43C‌​26D2-DCFF-4764-AAF0-‌​F6CC7BCDCF5D/data/Co‌​ntainers/Data/Applic‌​ation/8E49D340-7CAC-‌​4031-85BF-9E5C26A1E3‌​7A/Documents/Small-m‌​ario.png

How can I get image to displayed?

KAR
  • 3,303
  • 3
  • 27
  • 50

2 Answers2

3

Try using below code:

Get image path from Image name:

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

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

Set image using imageWithContentsOfFile method:

YourImageView.image = [UIImage imageWithContentsOfFile: imageFilePath]; 
Ronak Chaniyara
  • 5,335
  • 3
  • 24
  • 51
2

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

Albert Renshaw
  • 17,282
  • 18
  • 107
  • 195
Alfred
  • 136
  • 8
  • 1
    the question is laod image from local path not a server , at the same time question is tagged in objective C, can you modify your answer – Anbu.Karthik Aug 31 '16 at 12:33
  • 1
    `fileURLWithPath` is actually a valid solution for this. It will load the file from local path. – brandonscript Oct 05 '16 at 18:34
  • While this code snippet may answer the question, it doesn't provide any context to explain how or why. Consider adding a sentence or two to explain your answer. – brandonscript Oct 05 '16 at 18:35