在映像文件的路徑,你會得到資產的網址,並且可以使用該資產URL來顯示圖像在圖像視圖上。
首次進口
#import <AssetsLibrary/AssetsLibrary.h>
在你的項目,然後在UIImagePicker
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// You will get the image url like this
NSURL *imageURL = [info valueForKey:UIImagePickerControllerReferenceURL];
}
委託方法現在來顯示圖像,使用此代碼
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset) {
ALAssetRepresentation *rep = [myasset defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
if (iref) {
//here you get the image
largeimage = [UIImage imageWithCGImage:iref];
}
};
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:imageURL
resultBlock:resultblock
failureBlock:nil];
如果直接想要訪問該圖像,然後使用這個
UIImage* myImage=(UIImage*)[info objectForKey:@"UIImagePickerControllerOriginalImage"];
check(http://stackoverflow.com/questions/7777282/how-to-get-image-path-from-photo-library-and-how-to-retrieve-the-image-from-phot )。它會顯示如何獲取所選圖像的URL。 –
感謝您的回覆解決我的問題,但我想打開相機,然後單擊(使用此圖像)選項後點擊圖像沒有得到圖像路徑不顯示圖像如何解決這個 –
因爲你應該先保存圖像使用'ALAssetLibrary'然後只有你會得到點擊圖像和路徑。 –