简体   繁体   中英

How to get image gallery file path and display image using reference of file pathe

I want to get Gallery image file path and save this file path after close this view and open another view display this image using this file path reference ...

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{ 
NSLog(@"%@",info);

}

using this delegate how to get image file path and display this image another view

In the image file path you will get the url of asset, and you can use that asset url to display the image on image view.

First import

#import <AssetsLibrary/AssetsLibrary.h>

in you project, then in the delegate method of UIImagePicker

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
  // You will get the image url like this
  NSURL *imageURL = [info valueForKey:UIImagePickerControllerReferenceURL];
}

Now to display the image, use this code

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];

If you directly want to access the image then use this

UIImage* myImage=(UIImage*)[info objectForKey:@"UIImagePickerControllerOriginalImage"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM