1

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

  • 1
    check (http://stackoverflow.com/questions/7777282/how-to-get-image-path-from-photo-library-and-how-to-retrieve-the-image-from-phot). It will show how to get URL of selected image. – ChintaN -Maddy- Ramani Sep 04 '15 at 08:59
  • Thanks for your response resolve my problem but i want open the camera and click (use this image) option after click image does not get image path not display image how to resolve this – Rohit Rananaware Sep 04 '15 at 09:34
  • for that you should save image first using `ALAssetLibrary` then only you will get Clicked Image and Path. – ChintaN -Maddy- Ramani Sep 04 '15 at 09:38

1 Answers1

2

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"];
Rajat
  • 10,977
  • 3
  • 38
  • 55
  • Thanks Rajatp for your response above code resolve my problem but i want open the camera and click (use this image) option after click image does not get image path how to resolve this – Rohit Rananaware Sep 04 '15 at 09:30
  • You will not get the image path from camera, if you want you have to save that image to gallery then you will get path from asset. – Rajat Sep 04 '15 at 09:37
  • To do that check this link - http://stackoverflow.com/questions/4457904/iphone-how-do-i-get-the-file-path-of-an-image-saved-with-uiimagewritetosavedpho – Rajat Sep 04 '15 at 09:39
  • how to save image to gallery after click the photo – Rohit Rananaware Sep 04 '15 at 09:42
  • Cehck this link - http://stackoverflow.com/questions/4457904/iphone-how-do-i-get-the-file-path-of-an-image-saved-with-uiimagewritetosavedpho – Rajat Sep 04 '15 at 09:45
  • Thanks for My resolving problem. – Rohit Rananaware Sep 04 '15 at 10:04