本文介绍了在iOS 7中使用资产URL获取图像(UIImage)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的相册中有一些图像。我已经检索了所有这些资产的网址..我想使用资产网址获取特定图像...下面代码给了我资产网址..
I have some images in my Photo Album. I have already retrieved the asset urls of all of them.. I want to get a particular image using the asset url... below code gave me asset url..
ALAssetRepresentation *defaultRepresentation = [asset defaultRepresentation];
NSString *uti = [defaultRepresentation UTI];
NSURL *URL = [[asset valueForProperty:ALAssetPropertyURLs] valueForKey:uti];
现在使用此网址,如何获取图片(UIImage)?
Now using this url, how can I get the image(UIImage)?
推荐答案
通过此获取网址,
NSURL *url= (NSURL*) [[asset valueForProperty:ALAssetPropertyURLs] valueForKey:[[[asset valueForProperty:ALAssetPropertyURLs] allKeys] objectAtIndex:0]];
并从下面的网址获取图片。
And get image from url like below.
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *rep = [myasset defaultRepresentation];
@autoreleasepool {
CGImageRef iref = [rep fullScreenImage];
if (iref) {
UIImage *image = [UIImage imageWithCGImage:iref];
self.loadedImage = image;
dispatch_async(dispatch_get_main_queue(), ^{
//UIMethod trigger...
});
iref = nil;
}
}
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(@"Can't get image - %@",[myerror localizedDescription]);
};
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:yourUrl
resultBlock:resultblock
failureBlock:failureblock];
这篇关于在iOS 7中使用资产URL获取图像(UIImage)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!