請使用下面的代碼
typedef void (^ALAssetsLibraryAssetForURLResultBlock)(ALAsset *asset);
typedef void (^ALAssetsLibraryAccessFailureBlock)(NSError *error);
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset){
ALAssetRepresentation *rep = [myasset defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
if (iref){
dispatch_async(dispatch_get_main_queue(), ^{
UIImage *myImage = [UIImage imageWithCGImage:iref scale:[rep scale] orientation:(UIImageOrientation)[rep orientation]];
[fileImage addObject:myImage];
//binding ur UI elements in main queue for fast execution
//self.imageView.image = myImage;
});
}
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror){
//failed to get image.
};
ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease];
[assetslibrary assetForURL:[filePath objectAtIndex:0] resultBlock:resultblock failureBlock:failureblock];
注:確保,你[文件路徑objectAtIndex:0]將是一個NSUrl
對象。請將其轉換爲NSUrl
,如果不是。
實施例:
ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease];
NSURL myAssetUrl = [NSURL URLWithString:[filePath objectAtIndex:0]];
assetslibrary assetForURL:myAssetUrl resultBlock:resultblock failureBlock:failureblock];
可以表明,要存儲在陣列中的路徑.. – Leena 2012-07-30 13:16:06
資產庫://asset/asset.JPG ID = 1000000192&EXT = JPG文件路徑(陣列)是存儲用戶選擇的iPhone內置圖庫的圖像路徑。 Thx尋求幫助。 – user1562536 2012-07-31 09:54:32