How to get UIImagePicker selected image name?

主宰稳场 提交于 2019-12-18 17:36:13

问题


Does anyone know how to get the selected image name (the one from photo gallery) after presenting an UIImagePickerController?


回答1:


With the help of ALAsset you can able to achieve this.

Step 1: Get the Asset for the selected Image from the UIImagePicker

Step 2: Get the ALAssetRepresentation for that Asset.

Step 3: ALAssetRepresentation class has a property called 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.



来源:https://stackoverflow.com/questions/11471254/how-to-get-uiimagepicker-selected-image-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!