我想在关闭此 View 并使用此文件路径引用打开另一个 View 显示此图像后获取图库图像文件路径并保存此文件路径...
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSLog(@"%@",info);
}
使用这个委托(delegate)如何获取图像文件路径并在另一个 View 中显示此图像
最佳答案
在图像文件路径中,您将获得 Assets 的 url,您可以使用该 Assets url 在 ImageView 中显示图像。
首先导入
#import <AssetsLibrary/AssetsLibrary.h>
在你的项目中,然后在 UIImagePicker
的委托(delegate)方法中
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// You will get the image url like this
NSURL *imageURL = [info valueForKey:UIImagePickerControllerReferenceURL];
}
现在要显示图像,请使用此代码
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset) {
ALAssetRepresentation *rep = [myasset defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
if (iref) {
//here you get the image
largeimage = [UIImage imageWithCGImage:iref];
}
};
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:imageURL
resultBlock:resultblock
failureBlock:nil];
如果你想直接访问图像然后使用这个
UIImage* myImage=(UIImage*)[info objectForKey:@"UIImagePickerControllerOriginalImage"];
关于ios - 如何使用文件路径的引用获取图库文件路径并显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32393957/