Cross Platform
Android
iOS

Save Photo to App Directory

This recipe shows how to save a photo to an application’s Documents directory.

Recipe

The sample code uses the Camera helper from TweetStation to take a picture, and then demonstrates how to save it in the completion handler. The photo is saved to the applications Documents directory, like this:

TweetStation.Camera.TakePicture (this, (obj) =>{
   var photo = obj.ValueForKey(new NSString("UIImagePickerControllerOriginalImage")) as UIImage;
   var documentsDirectory = Environment.GetFolderPath
                         (Environment.SpecialFolder.Personal);
   string jpgFilename = System.IO.Path.Combine (documentsDirectory, "Photo.jpg"); // hardcoded filename, overwritten each time
   NSData imgData = photo.AsJPEG();
   NSError err = null;
   if (imgData.Save(jpgFilename, false, out err)) {
       Console.WriteLine("saved as " + jpgFilename);
   } else {
       Console.WriteLine("NOT saved as " + jpgFilename + " because" + err.LocalizedDescription);
   }
});

Additional Information

Saving the image data in this way does NOT include the metadata supplied by the camera (such as GPS location, camera model, exposure, etc).