简体   繁体   English

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

[英]How to distinguish capture image photo album selected image

how to distinguish between capture image and photo album Image 如何区分捕获图像和相册图像

After capture Image its show Retake or UsePhoto, On UsePhoto i am saving image to photo library and set to imageView. 捕获图像后,显示其Retake或UsePhoto,在UsePhoto上,我将图像保存到照片库并设置为imageView。

On Click Upload From album, selected image set to UIImageView 在单击“从相册上传”时,选定的图像设置为UIImageView

But for both case the delegate method will call. 但是对于这两种情况,都会调用委托方法。 Image upload from photo library or Image capture from the camera roll. 从照片库上传图像或从相机胶卷捕获图像。

Do not want to save image when selected photo library. 选择照片库时不想保存图像。

and save image when select the camera capture and "Use Photo". 并在选择摄像机捕获和“使用照片”时保存图像。

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];

}

You could use 你可以用

picker.sourceType picker.sourceType

to detect if the image was taken using the camera or if it was selected from camera roll. 检测图像是使用相机拍摄的还是从相机胶卷中选择的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM