How can I take a photo with my iPhone app?

前端 未结 5 1437
甜味超标
甜味超标 2021-01-31 19:39

I\'m writing an iPhone app with Cocoa in xcode. I can\'t find any tutorials or sample code that shows how to take photos with the built in camera. How do I do this? Where can

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-31 20:24

    Here is my code that i used to take picture for my app

    - (IBAction)takephoto:(id)sender {
    
        picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        [picker setSourceType:UIImagePickerControllerSourceTypeCamera];
        [self presentViewController:picker animated:YES completion:NULL];
    
    
    }
    -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
        img = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
        [imageview setImage:img];
        [self dismissViewControllerAnimated:YES completion:NULL];
    }
    

    if you want to retake picture just simple add this function

    -(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
    {
        [self dismissViewControllerAnimated:YES completion:NULL];
    }
    

提交回复
热议问题