如何获取UIImagePickerController选取的图像的原始文件名? [英] How to obtain the original file name of the image picked by UIImagePickerController?

查看:124
本文介绍了如何获取UIImagePickerController选取的图像的原始文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了委托方法并可以访问所选的UIImage,如下所示:

I've implemented the delegate method and can get access to the picked UIImage, like this:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    UIImage *pickedImage = [info valueForKey:UIImagePickerControllerOriginalImage];

我想将它保存到目录中,但我需要一个文件名。因此,选择与图像相同的文件名,而不仅仅是选择随机文件名。

I want to save it to a directory, but I need a file name. So rather than just picking a random file name it would make sense to pick the same file name as the image.

有没有办法从该信息字典中检索它?

Is there a way to retrieve it from that info dictionary?

推荐答案

您可以使用信息词典的 UIImagePickerControllerReferenceURL 值而不是 UIImagePickerControllerOriginalImage 。这应该会为您提供原始媒体项目的URL。

You could use the UIImagePickerControllerReferenceURL value of the info dictionary instead of the UIImagePickerControllerOriginalImage. This should give you the URL to the original media item.

这将返回一个 NSURL 对象,然后您可以用来构建你的新文件名。

This would return you a NSURL object which you then can use to build your new filename from.

这篇关于如何获取UIImagePickerController选取的图像的原始文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆