简体   繁体   English

如何获取UIImagePicker选定的图像名称?

[英]How to get UIImagePicker selected image name?

有人会在展示UIImagePickerController后知道如何获取选定的图像名称(从照片库中获得该名称)吗?

With the help of ALAsset you can able to achieve this. 借助ALAsset,您可以实现这一目标。

Step 1: Get the Asset for the selected Image from the UIImagePicker 步骤1:从UIImagePicker获取所选图像的Asset

Step 2: Get the ALAssetRepresentation for that Asset . 步骤2:获取该AssetALAssetRepresentation

Step 3: ALAssetRepresentation class has a property called fileName 步骤3: ALAssetRepresentation类具有一个名为fileName的属性

- (NSString *)filename

Returns a string representing the filename of the representation on disk. 返回一个表示磁盘上表示形式文件名的字符串。

This Sample Code will Helps you... 此示例代码将帮助您...

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

    NSURL *imageURL = [info valueForKey:UIImagePickerControllerReferenceURL];
    ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
    {
        ALAssetRepresentation *representation = [myasset defaultRepresentation];
        NSString *fileName = [representation filename];
        NSLog(@"fileName : %@",fileName);
    };

    ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease];
    [assetslibrary assetForURL:imageURL 
                   resultBlock:resultblock
                  failureBlock:nil];

}

NOTE: It works only in iOS 5 and later. 注意:它仅在iOS 5和更高版本中有效。

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

相关问题 如何在 UIImagePicker 控制器中保存选定的图像? - How to save the selected image in UIImagePicker controller? 如何使用UIImagePicker获取图像名称? 我得到了图像名称,但它仅在模拟器中有效,而在实际设备中无效 - How to get image name using UIImagePicker? I got image name but its working only in simulators not in actual devices 如何在iOS的某些文件输入字段上通过UIWebView中的UIImagePicker选择图像? - How do I get image selected by UIImagePicker in UIWebView on certain file input field in iOS? 从NSURL UIImagepicker Controller iOS 9获取图像名称 - Get the image name from NSURL UIImagepicker Controller iOS 9 如何在iOS上的UIImagePicker中获取实际图像帧的大小? - How to get the size of the actual image frame inside UIImagePicker on iOS? 选择图像后,UIImagePicker重新出现 - UIImagePicker reappears after being image is selected 如何获得所选图像的“文件名” - How to get the 'file's name' of image selected 将选定的图像从UIImagePicker传递到第二个View Controller - Passing Selected Image from UIImagePicker to a Second View Controller 如何从UIImagePicker检测图像是否为横向 - How to detect if image is landscape from UIImagePicker 如何为图像添加属性UIImagePicker Swift 4 - How to Add Properties For Image UIImagePicker Swift 4
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM