iPhone: How do I get the file path of an image saved with UIImageWriteToSavedPhotosAlbum()?

I finally found out the answer.
Apparently the UIImage methods strip out metadata and so using UIImageWriteToSavedPhotosAlbum is no good.

However in ios4 Apple put in a new framework to handle the photo library called the ALAssetsLibrary.

First you need to right click on the Targets and in the build part, add the AlAsset Framework to your project with the little + icon in the bottom left.

Then add #import "AssetsLibrary/AssetsLibrary.h"; to the header file of your class.

Finally you can use the following code:

UIImage *viewImage = YOUR UIIMAGE  // --- mine was made from drawing context
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];  
// Request to save the image to camera roll  
[library writeImageToSavedPhotosAlbum:[viewImage CGImage] orientation:(ALAssetOrientation)[viewImage imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){  
    if (error) {  
        NSLog(@"error");  
    } else {  
            NSLog(@"url %@", assetURL);  
    }  
}];  
[library release];

And that gets the path of the file you just saved.

Leave a Comment