Save Photo to App Directory

PDF for offline use
Sample Code:
Related Articles:
Related SDKs:

Let us know how you feel about this

Translation Quality


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


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
   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).

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.