Skip to content

Instantly share code, notes, and snippets.

@prashantvc
Created September 28, 2015 08:07
Show Gist options
  • Save prashantvc/b6d5ae62fc69c501f215 to your computer and use it in GitHub Desktop.
Save prashantvc/b6d5ae62fc69c501f215 to your computer and use it in GitHub Desktop.
public class Camera
{
void TakePicture (object sender, EventArgs args)
{
Init ();
picker.SourceType = UIImagePickerControllerSourceType.Camera;
_callback = Callbak;
PresentViewController (picker, true, null);
}
void Callbak (NSDictionary dic)
{
Console.WriteLine (dic);
var image = dic.ObjectForKey (new NSString ("UIImagePickerControllerOriginalImage")) as UIImage;
image.SaveToPhotosAlbum (new UIImage.SaveStatus(delegate(UIImage img, NSError error) {
Console.WriteLine (img);
}));
}
static UIImagePickerController picker;
static Action<NSDictionary> _callback;
static void Init ()
{
if (picker != null)
return;
picker = new UIImagePickerController ();
picker.Delegate = new CameraDelegate ();
}
class CameraDelegate : UIImagePickerControllerDelegate
{
public override void FinishedPickingMedia (UIImagePickerController picker, NSDictionary info)
{
var cb = _callback;
_callback = null;
picker.DismissViewController (true, null);
cb (info);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment