これを使用して画像をストレージに保存しました:
UIImageWriteToSavedPhotosAlbum(image, self,
@selector(image:didFinishSavingWithError:contextInfo:), nil);
では、その画像を画像ビューにロードするにはどうすればよいでしょうか?
画像ビューにはimage
プロパティがあります。それに画像を割り当てます。
編集:フォト アルバムのエントリへの永続的な参照を保存する場合は、その機能を使用して保存しないでくださいwriteImageToSavedPhotosAlbum:metadata:completionBlock:
。代わりに使用してください。完了ブロックにはassetURL
パラメーターが渡されます。
これは私が今使用しているコードです:
//Load the asset URL from my photo object
NSURL *asseturl = [NSURL URLWithString:photo.photoURL];
ALAssetsLibrary* myasset = [[ALAssetsLibrary alloc] init];
//If the image was found
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *rep = [myasset defaultRepresentation];
//Get the full resolution image
CGImageRef iref = [rep fullResolutionImage];
if (iref) {
//Get the orientation of the image
ALAssetOrientation orientation = [[myasset valueForProperty:@"ALAssetPropertyOrientation"] intValue];
//Set the image view image
[self.BigImageView setImage:[UIImage imageWithCGImage:iref scale:1.0 orientation:orientation]];
}
};
//If the image isn't available
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(@"Can't get the image - %@",[myerror localizedDescription]);
[self.BigImageView setImage:nil];
};
[myasset assetForURL:asseturl
resultBlock:resultblock
failureBlock:failureblock];