views:

160

answers:

0

I am trying to write an application, but it is constantly crashing when using the uiimagepickercontroller. I thought that it might be because I was not disposing of the picker after each use, but it will often freeze up on first run as well. Usually I'll take a picture and it just freezes, never asking to "use" the picture.

Do you have any suggestions? Here is my code. Has anyone gotten this to work?

 public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();

        myPicker = new UIImagePickerController();
        myPicker.Delegate = new myPickerDelegate(this);

        myAlbumButton.Clicked += delegate {
                if(UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary)){
                    myPicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary;
                    myPicker.AllowsEditing = true;
                    this.PresentModalViewController (myPicker, true);
                }else{
                Console.WriteLine("cannot get album");  
            }
        };


        myCameraButton.Clicked += delegate {
            if(UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)){
                myPicker.SourceType = UIImagePickerControllerSourceType.Camera;
                //myPicker.AllowsEditing = true;
                this.PresentModalViewController (myPicker, true);
            }else{
                Console.WriteLine("cannot get camera"); 
            }

        };

    }


    private class myPickerDelegate : UIImagePickerControllerDelegate
    {
        private TestView _vc;

        public myPickerDelegate ( TestView controller):base()
        {
            _vc = controller;   
        }

        public override void FinishedPickingImage (UIImagePickerController myPicker, UIImage image, NSDictionary editingInfo)
        {
            // TODO: Implement - see: http://go-mono.com/docs/index.aspx?link=T%3aMonoTouch.Foundation.ModelAttribute

            _vc.myImageView.Image = image;
            myPicker.DismissModalViewControllerAnimated(true);
        }
 }