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?
views:
327answers:
2
+2
A:
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];
}
Raj
2009-04-21 13:41:54
A:
Hi Raj,
Can I want to show user that they using a photo but also want to store that using the above technique. Here's my code:
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo {
imageView.image = image;
[picker dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissModalViewControllerAnimated:YES];
}
Can I place your code in after my "imageView.image =image?" line?
Michael Robinson
2010-01-05 22:53:47