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)
![Oiproks](https://i.stack.imgur.com/MxpdO.png?s=256&g=1)
Comments
-
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 over 12 yearsOk... I did this. The main reason why it wasn't working is... the UIImageView was hidden. I'm an idiot! Thanks anyway.
-
思齐省身躬行 almost 7 yearsIt's recommended to use UIImage(contentsOfFile: imagePath).
-
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