use*_*065 3 image uiimagepickercontroller ios
有人知道如何在呈现UIImagePickerController后获取所选图像名称(来自照片库的图像名称)吗?
Ara*_*han 10
在ALAsset的帮助下,您可以实现这一目标.
第1步:Asset
从中获取所选图像UIImagePicker
第2步:获取ALAssetRepresentation为Asset
.
第3步:ALAssetRepresentation
类有一个名为的属性fileName
- (NSString *)filename
Run Code Online (Sandbox Code Playgroud)
返回表示磁盘上表示的文件名的字符串.
此示例代码将帮助您......
- (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];
}
Run Code Online (Sandbox Code Playgroud)
注意:它仅适用于iOS 5及更高版本.