user564968
user564968

Reputation:

how can we get image from local?

I store image in local by this code...

NSData *imageData = UIImagePNGRepresentation(image);
NSString *imageName = [NSString stringWithFormat:@"image.png"];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imageName];

[imageData writeToFile:fullPathToFile atomically:YES];

I can see this image in my iphone simulator bundle ...but how can i get back this image ?

Upvotes: 1

Views: 225

Answers (1)

Jacob Relkin
Jacob Relkin

Reputation: 163308

If you mean recreate the image from a file, you can do that very simply by using UIImage's +imageWithContentsOfFile: method:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPathToFile = [documentsDirectory stringByAppendingPathComponent:@"someImageName"];
UIImage *image = [UIImage imageWithContentsOfFile:fullPathToFile];

Upvotes: 2

Related Questions