Using the iOS AVFoundation sdk in Xamarin to take a picture and save to the image gallery

Using the AVFoundation you can capture still images from your app, convert to a CIImage, obtain a mutable copy of its metadata (you can add custom properties), then save to the device's image gallery:


async void TakePhotoButtonTapped(UIButton sender)
var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);

var sampleBuffer = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);

var jpegImageAsNsData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);

var image = CIImage.FromData(jpegImageAsNsData);

var metaData = image.Properties.Dictionary.MutableCopy() as NSMutableDictionary;

var library = new ALAssetsLibrary();

library.WriteImageToSavedPhotosAlbum(jpegImageAsNsData, metaData, (assetUrl, error) => 
Console.WriteLine ("assetUrl:"+assetUrl);