문제

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];
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top