I'm writing an app that allows the user to take a picture and then shows it in an image view.
I get that I need to write a line of code similar to the following: _imageView.image = picker.image;
, but I'm not sure what I need to substitute for picker.image
. That is what I currently have and it gives me an error.
Basically, what I'm asking is how do I reference the picture that was just taken? Where does this picture go (in memory?) after you take it? How can I reference it later (like for displaying and saving and that sort of stuff)?
I've already read the official Apple documentation and looked at a few tutorials and the answer doesn't seem to be in any of them. As I've mentioned in previous posts, I tend to have a lot of trouble parsing the Apple documentation, so it's been mostly useless for me.
Thank you!
I use the following delegate method to get whatever picture a user picked from the photo picker view
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:false completion:nil];
image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}
call the cameraTapped method on tapping your camera button
-(IBAction)cameraTapped:(id)sender
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
[imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
else
[imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[imagePickerController setDelegate:self];
[self presentViewController:imagePickerController animated:YES completion:nil];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// photo
_imageView.image = info[UIImagePickerControllerOriginalImage]];
[self dismissViewControllerAnimated:YES completion:nil];
}