![](/img/trans.png)
[英]How to get the path of an photo in camera roll or just taken ( iOS/Swift )?
[英]iPad: retrieve filename of photo just taken using built-in camera and pass it to other function for further image processing
大家好,我是iOS编程的新手,我正在开发一个iPad应用程序,该应用程序使用iOS内置相机拍摄照片,然后使用所拍摄的照片在Background中进行图像处理(OpenCV)。 无需向用户显示图像处理。 拍摄后我想处理图像。 但是我不知道刚刚拍摄的照片如何通过(照片保存在相机胶卷中,文件名IMG_XXXX.jpg的数量(XXXX)不断增加)。 那么,如何获取刚刚拍摄的照片的文件名,并将其传递给函数,以便使用OpenCV进行进一步的图像处理?
我使用以下两个功能来拍摄和保存照片。
// take photo
- (IBAction)captureCamera:(id)sender {
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = @[(NSString *) kUTTypeImage];
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker animated:YES completion:nil];
_newMedia = YES; // a photo has been taken
}
}
// save photo
#pragma mark -
#pragma mark UIImagePickerControllerDelegate
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = info[UIImagePickerControllerMediaType];
[self dismissViewControllerAnimated:YES completion:nil];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
UIImage *image = info[UIImagePickerControllerOriginalImage];
_imageView.image = image;
if (_newMedia)
UIImageWriteToSavedPhotosAlbum(image, self,
@selector(image:finishedSavingWithError:contextInfo:),
nil); }
saveimg = true; // if an image is saved
if (saveimg == true)
{
//imgprocess(); // pass the photo just taken for further image processing
}
saveimg = false; // reset it for next photo-taking
}
非常感谢您的帮助!
AssetLibrary可以通过以下方法为您提供资产枚举功能: enumerateGroupsWithTypes:usingBlock:failureBlock:
但现在您必须尝试看看它是否提供了最后一个对象路径,即是否保存了最新的对象路径。
祝你好运
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.