Cross Platform
Android
iOS
Test Cloud

Save Photo to Album with Metadata

This recipe shows how to save a photo to the Photos Camera Roll Album, including image metadata.

Recipe

The sample code uses the  Camera helper from TweetStation to take a picture, then demonstrates how to save it (with metadata) in the completion handler:

TweetStation.Camera.TakePicture (this, (obj) =>{
    var photo = obj.ValueForKey(new NSString("UIImagePickerControllerOriginalImage")) as UIImage;
    var meta = obj.ValueForKey(new NSString("UIImagePickerControllerMediaMetadata")) as NSDictionary;
    ALAssetsLibrary library = new ALAssetsLibrary();                   
    library.WriteImageToSavedPhotosAlbum (photo.CGImage, meta, (assetUrl, error) =>{
        Console.WriteLine ("assetUrl:"+assetUrl);
    });
});;

Additional Information

There is a simpler mechanism to save an existing UIImage to the Photo Album, but it does not include metadata:

var someImage = UIImage.FromFile("someImage.jpg");
someImage.SaveToPhotosAlbum((image, error) => {
    var o = image as UIImage;
    Console.WriteLine("error:" + error);
});