Initialize a UIImage with the path of an image

22,437

Solution 1

Use + (UIImage *)imageWithContentsOfFile:(NSString *)path

UIImage *image = [UIImage imageWithContentsOfFile:imagePath];

Solution 2

Swift 3.0 code here..

use contentsOfFile

imageView.image = UIImage.init(contentsOfFile: imagePath)
Share:
22,437
Oiproks
Author by

Oiproks

Code for work, code for fun, code when bored...

Updated on July 31, 2020

Comments

  • Oiproks
    Oiproks almost 4 years

    I have in a sqlite database the complete path of an image, which is stored in the device, and I need to set a UIImage with that image.

    Example:

    NSLog(@"Path %@", imagePath);
    

    Output:

    /Users/Sk*****/Library/Application Support/iPhone Simulator/4.3.2/Applications/15977219-DEFE-407A-BB80-72E188E18DD2/Documents/20-10-20111746.png
    
  • Oiproks
    Oiproks over 12 years
    Ok... I did this. The main reason why it wasn't working is... the UIImageView was hidden. I'm an idiot! Thanks anyway.
  • 思齐省身躬行
    思齐省身躬行 almost 7 years
    It's recommended to use UIImage(contentsOfFile: imagePath).
  • Arjun Yadav
    Arjun Yadav almost 7 years
    @user5685969 If you want to show the Image path in your device then you should use this one but your code is before version swift 3.0