有谁知道如何在呈现 UIImagePickerController 后获取所选图像名称(来自照片库的图像名称)?
最佳答案
在ALAsset的帮助下你可以做到这一点。
第 1 步:从 UIImagePicker
中获取所选图像的 Asset
第 2 步:获取 ALAssetRepresentation对于那个 Asset
。
第 3 步:ALAssetRepresentation
类有一个名为 fileName
的属性
- (NSString *)filename
返回一个字符串,表示磁盘上表示的文件名。
此示例代码将帮助您...
- (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];
}
注意:它仅适用于 iOS 5 及更高版本。
关于ios - 如何获取 UIImagePicker 选中的图片名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11471254/