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
Once a UIImage is created, the image data is loaded into memory and no longer connected to the file on disk. As such, the file can be deleted or modified without consequence to the UIImage and there is no way of getting the source path from a UIImage.
For example: UIImage *img = [[UIImage alloc] init]; [img setImage:[UIImage imageNamed:@"anyImageName"]]; My UIImage object is declared in . h file and allocated in init method, I need to set image in viewDidLoad method.
UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage .
Use + (UIImage *)imageWithContentsOfFile:(NSString *)path
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
Swift 3.0 code here..
use contentsOfFile
imageView.image = UIImage.init(contentsOfFile: imagePath)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With