如何确定图像是从库中还是从相机中拍摄的

时间:2014-04-21 15:57:57

标签: ios objective-c image if-statement

我想通过if语句检查是从相机胶卷中拾取图像还是由内置相机拍摄的。我怎么能通过if语句来做到这一点? 谢谢你的帮助!

代码:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{

if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {

    toolbar.hidden = NO;
}

if (picker.sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {

    toolbar.hidden = NO;
}

if (picker.sourceType == UIImagePickerControllerSourceTypeSavedPhotosAlbum) {

    toolbar.hidden = NO;
}

else{

    toolbar.hidden = YES;
}

imgView.image = [info objectForKey:@"UIImagePickerControllerEditedImage"];

[self dismissViewControllerAnimated:YES completion:nil];
}

1 个答案:

答案 0 :(得分:4)

只需查看sourceType

即可
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
    //image taken with camera
}
else{
    //image taken from camera roll
}

imagePickerController:didFinishPickingMediaWithInfo:方法中执行此操作。