2

What I am doing is to save an image loaded from any source,(camera / library) and saving it to filesystem in iOS. What I m stuck is at how I can use that save image.. I m using the following code. Its working it is creating a Test.jpg in Documents Folder. But Really have no idea how to access this Test.jpg.

NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.jpg"];
[UIImageJPEGRepresentation(selectedImage.image, 1.0) writeToFile:jpgPath atomically:YES];
NSError *error;
NSFileManager *fileMgr = [NSFileManager defaultManager];  
NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
tshepang
  • 12,111
  • 21
  • 91
  • 136
Arsalan Haider
  • 559
  • 3
  • 9
  • 23

2 Answers2

17

Use this method:

let testImage = UIImage(contentsOfFile: filePath)

imageNamed looks for an image with the specified name in the application’s main bundle.

beryllium
  • 29,669
  • 15
  • 106
  • 125
  • 1
    If you want to cache image from Documents directory then see [Any way to get a Cached UIImage from my 'Documents' directory?](http://stackoverflow.com/questions/1338727/any-way-to-get-a-cached-uiimage-from-my-documents-directory) – beryllium Nov 26 '11 at 11:55
3

In Swift:

let testImage = UIImage(contentsOfFile: filePath)
NatashaTheRobot
  • 6,879
  • 4
  • 32
  • 27