SaveToAlbum function is not working in my iOS app

ChrisDeBrodie.OAChrisDeBrodie.OA USUniversity ✭✭
edited January 2016 in Xamarin.iOS

hello I am working on a iOS app that open's the camera and takes a picture then saves it to the camera roll how ever when I hit the use photo button the app crashes

Here's my code:

using Foundation;
using System;
using System.CodeDom.Compiler;
using UIKit;

namespace ToolBelt.iOS
{
    partial class CameraView : UIViewController

    {
        public CameraView (IntPtr handle) : base (handle)
        {       
        }



        public override void DidReceiveMemoryWarning ()
        {
            // Releases the view if it doesn't have a superview.
            base.DidReceiveMemoryWarning ();

            // Release any cached data, images, etc that aren't in use.
        }

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


            //UIPopoverController popover = new UIPopoverController (ctrl);

            // Perform any additional setup after loading the view, typically from a nib.
        }




        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            if (imageView.Image == null)
            {
                UIImagePickerController picker = new UIImagePickerController();

                picker.SourceType = UIImagePickerControllerSourceType.Camera;
                picker.Delegate = this;
                PresentViewController(picker, true, null);
            }
        }

        [Export("imagePickerController:didFinishPickingImage:editingInfo:")]
        public void FinishedPickingImage(UIKit.UIImagePickerController picker, UIKit.UIImage image, Foundation.NSDictionary editingInfo)
        {
            var someImage = UIImage.FromFile("someImage.jpg");
            someImage.SaveToPhotosAlbum((pic, error) =>
                {
                    var o = pic as UIImage;
                    Console.WriteLine("error:" + error);
                });
            DismissViewController(true, null);

        }
    }


}

what am I doing wrong?

any help would be amazing

Thanks in advance!

Answers

  • DaveHuntDaveHunt USMember ✭✭✭✭✭

    What does the crash information show? e.g. exception, stacktrace, etc.

  • ChrisDeBrodie.OAChrisDeBrodie.OA USUniversity ✭✭

    Dave Hunt Thanks for the reply! Here's what i'm getting:

    Unhandled Exception:

    System.NullReferenceException: Object reference not set to an instance of an object

    and its reflecting this code:

       var someImage = UIImage.FromFile("someImage.jpg");
            someImage.SaveToPhotosAlbum((pic, error) =>
                {
                    var o = pic as UIImage;
                    Console.WriteLine("error:" + error);
                });
    

    any ideas?

    Thanks in advance :)

  • DaveHuntDaveHunt USMember ✭✭✭✭✭

    On what line does the error occur? What does the debugger say the value of someImage is?

    I suspect the problem is that UIImage.FromFile failed to load the specified file and returned null. In that case, make sure the image you are trying to load actually exists and that you specify the path to that image.

Sign In or Register to comment.