Created
September 28, 2015 08:07
-
-
Save prashantvc/b6d5ae62fc69c501f215 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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