的API有所改变了规则,你没有得到直接的文件系统访问iPhoto图库任何更多。相反,您可以像这样获取资产库网址。
assets-library://asset/asset.JPG?id=1000000003&ext=JPG
您使用ALAssetLibrary对象通过URL来访问ALAsset对象。
所以从文档的ALAssetLibrary抛出这个在报头(或源)
typedef void (^ALAssetsLibraryAssetForURLResultBlock)(ALAsset *asset);
typedef void (^ALAssetsLibraryAccessFailureBlock)(NSError *error);
这心不是严格必要的,但很让事情。
然后在你的来源。
-(void)findLargeImage
{
NSString *mediaurl = [self.node valueForKey:kVMMediaURL];
//
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *rep = [myasset defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
if (iref) {
largeimage = [UIImage imageWithCGImage:iref];
[largeimage retain];
}
};
//
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(@"booya, cant get image - %@",[myerror localizedDescription]);
};
if(mediaurl && [mediaurl length] && ![[mediaurl pathExtension] isEqualToString:AUDIO_EXTENSION])
{
[largeimage release];
NSURL *asseturl = [NSURL URLWithString:mediaurl];
ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease];
[assetslibrary assetForURL:asseturl
resultBlock:resultblock
failureBlock:failureblock];
}
}
几件事情需要注意的是,这里使用之前,我开始了我的iOS4移植这是新的给我块,但你可能想看看
https://www.mikeash.com/pyblog/friday-qa-2008-12-26.html
和
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Blocks/Articles/00_Introduction.html
他们弯曲你的头,但如果你认为他们作为通知选择器或回调它有帮助。
而且
findLargeImage
返回 resultblock不会有作为 回调尚未运行时。所以largeImage不会是 有效。
largeImage
需要是一个 实例变量,其范围不在 方法中。
我使用这种构造来做到这一点,当使用该方法,但你可能会发现更适合你的使用方法。
[node.view findLargeImage];
UIImage *thumb = node.view.largeImage;
if (thumb) { blah blah }
那就是我在试图让这个工作时学到的东西。
iOS 5的更新
当结果框大火似乎有点慢iOS5的&也许单核设备,使我不能依靠在图像上调用findLargeImage
后直接可用。所以我将它改为致电代表。
@protocol HiresImageDelegate <NSObject>
@optional
-(void)hiresImageAvailable:(UIImage *)aimage;
@end
和COMMECá
//
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *rep = [myasset defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
if (iref) {
UIImage *largeimage = [UIImage imageWithCGImage:iref];
[delegate hiresImageAvailable:large];
}
};
我想出做到这一点的一种方法:\t ALAssetRepresentation * assetRep = [资产defaultRepresentation]; UIImage * image = [UIImage imageWithCGImage:[assetRep fullResolutionImage]]; 但我想通过URL访问它。帮助... – Bangdel 2010-10-01 08:43:08