如何区分捕获图像相册选择的图像

时间:2014-10-15 14:13:15

标签: ios objective-c iphone camera uiimagepickercontroller

如何区分捕获图像和相册图像

捕获图像后显示Retake或UsePhoto,On UsePhoto我将图像保存到照片库并设置为imageView。

点击上传从相册,所选图像设置为 UIImageView

但是对于这两种情况,委托方法都会调用。从照片库上传图像或从相机胶卷中捕获图像。

选择照片库时不想保存图像。

选择相机拍摄和“使用照片”时

并保存图像。

imageview.image = image;

-(void)imageUploaded:(NSInteger)selectedIndex{
    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;

    if (selectedIndex == 0){
        picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
        [self.navigationController presentViewController:picker animated:YES completion:nil];

    }
    else if (selectedIndex == 1){

        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        [self presentViewController:picker animated:YES completion:nil];
    }

    else if (selectedIndex == 2) {
        NSLog(@"Zero Index ");
    }
}

- (void)imagePickerController:(UIImagePickerController *)picker
        didFinishPickingImage:(UIImage *)image
                  editingInfo:(NSDictionary *)editingInfo{

    if(image != nil){
     UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
     imageview.image = image;
    }
    [picker dismissViewControllerAnimated:YES completion:Nil];

}

1 个答案:

答案 0 :(得分:2)

您可以使用

  

picker.sourceType

检测图像是使用相机拍摄的,还是从相机胶卷中选择的。