[英]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:获取该
Asset
的ALAssetRepresentation 。
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.