Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initialize a UIImage with the path of an image

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
like image 610
Oiproks Avatar asked Oct 20 '11 18:10

Oiproks


People also ask

How do I find my UIImage path?

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.

How do you declare UIImage in Objective C?

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.

What is the difference between a UIImage and a UIImageView?

UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage .


2 Answers

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

UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
like image 86
epatel Avatar answered Oct 24 '22 10:10

epatel


Swift 3.0 code here..

use contentsOfFile

imageView.image = UIImage.init(contentsOfFile: imagePath)
like image 33
Arjun Yadav Avatar answered Oct 24 '22 11:10

Arjun Yadav