如何获得UIImagePickerselect的图像名称?
有谁知道如何获得选定的图像名称(从照片库中的一个)后呈现一个UIImagePickerController?
在ALAsset的帮助下,您可以实现这一点。
第1步:从UIImagePicker
获取所选图像的Asset
第2步:获取该Asset
的ALAssetRepresentation 。
第3步: ALAssetRepresentation
类有一个名为fileName
的属性
- (NSString *)filename
返回表示磁盘上表示的文件名的string。
这个示例代码将帮助你…
- (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及更高版本。