How do I save a reference to a specific photo on iPhone for loading without picker?
Question
A user can select a photo from their library using the image picker - I want to remember this selection and display this picture in future without the user having to pick it. How can I reference the specific photo or is there a way I can copy the photo to my application's storage?
Solution
you can save the selected image by converting it into NSData object and then writing it on the iphone file system under your app's document directory like this:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
NSData *imageData = UIImagePNGRepresentation(image);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filename = [documentsDirectory stringByAppendingPathComponent:@"SavedImage"];
[imageData writeToFile:filename atomically:NO];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow