0

I have just started developing an application in which I want to auto sync all the images stored in user's photo library as assets.

I am able to get URL for images those are stored as assets.

e.g. assets-library://asset/asset.JPG?id=1000000003&ext=JPG

Now, how do I copy this image in to document's directory of my application or how do I just display image stored in assets by getting that in NSData or in UIImage?

Thanks in Advance.

Jhaliya - Praveen Sharma
  • 31,697
  • 9
  • 72
  • 76
Ruchir Agile
  • 537
  • 1
  • 5
  • 4

1 Answers1

1

You can use the following code in UIImagePickerControllerDelegate delegate implementation

- (void) imagePickerController:(UIImagePickerController *)picker
 didFinishPickingMediaWithInfo:(NSDictionary *)info {

    //obtaining saving path
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *imagePath = [documentsDirectory stringByAppendingPathComponent:@"my_photo.png"];

    //extracting image from the picker and saving it
    UIImage *editedImage = [info objectForKey:UIImagePickerControllerEditedImage];
    NSData *imageData = UIImagePNGRepresentation(editedImage);
    [imageData writeToFile:imagePath atomically:YES];

}
Jhaliya - Praveen Sharma
  • 31,697
  • 9
  • 72
  • 76
  • 1
    @RuchirAgile, as soon as you get the asset, copy it right away as @Jhaliya suggests. – Black Frog Apr 13 '11 at 12:15
  • I am not using ImagePickerController as using ImagePicker you can get only one image at a time. I want to sync/get all the photos on my app launch. – Ruchir Agile Apr 13 '11 at 12:44