UIImagePickerController is showing last clicked image

RaghavSukhwal.4674RaghavSukhwal.4674 Raghav SukhwalUSMember
edited November 2013 in iOS

In my project, when I launch camera first time it works fine. when I launch camera second time, I see image last clicked in view finder. I am not sure what's causing this.

Can anyone please help me here?


  • RaghavSukhwal.4674RaghavSukhwal.4674 Raghav Sukhwal USMember

    here is my code to launch camera.

    UIImagePickerController imagePicker = new UIImagePickerController();
    // Handle media selected.
    var documentsDirectory = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
    imagePicker.FinishedPickingMedia += (sender, e) => {
    UIImage image = (UIImage)e.Info.ObjectForKey(
    new NSString("UIImagePickerControllerOriginalImage"));

            if (image != null)
    this.InvokeOnMainThread(() => {
    this.clickedImage.Image = image;
    image.SaveToPhotosAlbum(delegate(UIImage img, NSError err){
    string pngFilename = System.IO.Path.Combine (documentsDirectory, "Photo.png"); // hardcoded filename, overwrites each time
    NSData imgData = image.AsPNG();
    NSError SaveErr = null;
    if (imgData.Save(pngFilename, false, out SaveErr))
    Console.WriteLine("saved as " + pngFilename);
    } else {
    Console.WriteLine("NOT saved as" + pngFilename + " because" + SaveErr.LocalizedDescription);



    // Handle cancellation of picker.
    imagePicker.Canceled += (sender, e) => {


    btnCameraDisplay1.SetTitle("Take Picture", UIControlState.Normal);
    btnCameraDisplay1.Font = UIFont.SystemFontOfSize(19);
    btnCameraDisplay1.SetTitleColor(UIColor.Black, UIControlState.Normal);

    btnCameraDisplay1.TouchUpInside += delegate(object sender, EventArgs e)
    imagePicker.SourceType = UIImagePickerControllerSourceType.Camera;
    imagePicker.AllowsEditing = false;
    this.PresentViewController(imagePicker, true,null);
    alertView = new UIAlertView();
    alertView.Message = "No camera available in this device.";
    alertView.AlertViewStyle = UIAlertViewStyle.Default;
  • RaghavSukhwal.4674RaghavSukhwal.4674 Raghav Sukhwal USMember

    Hi there,

    Any help/hint on this?

  • JamesBryanJamesBryan James Bryan USMember
    edited February 7


    Place this after you have have used imagePicker.DismissViewController();

    I place it in the parent UIViewController. This is after I have saved the image.

    This error gave me a lot of grief but so far so good.

    Thanks to Shaddix on stack overflow. I can't believe I didn't remember that little gem myself.

Sign In or Register to comment.