0

How can I save the images to iPad's Gallery, and again read them from there into my App. Is it possible to create a folder structure in iPad's gallery where I could store images generated through my app.

Actually I am able to save the images to gallery, I am using this

UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);

But don't know how to load it back into app from gallery. ?

Prashant Nikam
  • 2,253
  • 4
  • 17
  • 29

1 Answers1

0

Use the ALAssetsLibrary, then you can call writeImageToSavedPhotosAlbum:metadata:completionBlock: to save the image and in the completion block you get the assetURL. This can later be used to get the image back from the library.


Docs are here .

To get the image for the asset url:

[self.assetsLibrary assetForURL:imageURL resultBlock:^(ALAsset *asset) {
    if (asset != nil) {
        imageView.image = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]];
     }
} failureBlock:^(NSError * error) {
    NSLog (@"Error getting image asset: %@", error);
}];
Wain
  • 118,658
  • 15
  • 128
  • 151
  • can u share a link to some sample code, if u have...because I have no idea about what ALAssetsLibrary is.. – Prashant Nikam Aug 05 '13 at 14:57
  • can u elaborate your answer little bit...I am able to save the image now, but dont know how to read it.. – Prashant Nikam Aug 06 '13 at 12:55
  • I think URL doesn't static in photoGallery. So answer is not possible. – TheTiger Aug 06 '13 at 13:05
  • @TheTiger, in some cases no asset could be returned, this would happen if the asset was deleted, user denied access, the asset is from photo stream and has been disconnected... – Wain Aug 06 '13 at 13:08
  • But URL would be change in case of adding the image into photo gallery too which is very basic. – TheTiger Aug 06 '13 at 13:09
  • The URL is the asset URL after it has been added to the photo library, that is why it is returned in the completion block called after the image has been saved. @TheTiger – Wain Aug 06 '13 at 13:20
  • Actually I just want to say that when user will save new pic in photo gallery the URL of image can be change it would be the same as it was before. is not it ? I think it is. So you can't specify the image from url from photo gallery ... It would create the problem. – TheTiger Aug 06 '13 at 16:23