[英]How to determine whether an image was taken from the library or from the camera
I want to check via an if statement if an image is picked from the camera roll or is taken by the built in camera. 我想通过if语句检查是否从相机胶卷中拾取图像或由内置相机拍摄图像。 How can I do this via an if-statement? 如何通过if语句执行此操作? Thanks for your help! 谢谢你的帮助!
Code: 码:
- (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];
}
Simply check the sourceType
: 只需检查sourceType
:
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
//image taken with camera
}
else{
//image taken from camera roll
}
Do this in your imagePickerController:didFinishPickingMediaWithInfo:
method. 在imagePickerController:didFinishPickingMediaWithInfo:
方法中执行此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.