有什么办法能根据Asset的url直接读取相册的原图片呢?
比如把相册照片的url存放到数据库中,后面怎么取出来呢?
直接上代码:
//从照片库加载原图片
ALAssetsLibrary* assetsLibrary = [[ALAssetsLibrary alloc] init];
NSURL *url=[NSURL URLWithString:[dic objectForKey:@"url"]];
[assetsLibrary assetForURL:url resultBlock: ^(ALAsset *asset){
ALAssetRepresentation *representation = [asset defaultRepresentation];
CGImageRef imageRef = [representation fullResolutionImage];
if (imageRef) {
UIImage *origianalImage = [UIImage imageWithCGImage:asset.defaultRepresentation.fullResolutionImage];
}
} failureBlock: ^(NSError *error)
{
// error handling
NSLog(@"failure-----");
}];
当然获取到照片后,可以用delegate等回调模式通知调用者。