0

I have a Windows Mobile (Compact framework 2) application that defines a user control MPhotoControl. MPhotoControl shows a default image and when the user clicks on this image a CameraCaptureDialog is opened to allow a photo to be captured. Once captured, the photo is then displayed in the user control. This works fine for capturing a single photo and then going back to the application.

The problem is that when there are lots of these controls on a particular form then the user interface becomes very unfriendly because the user has to show the camera dialog, take a photo, save and close the dialog for every photo control on the form. What the users are asking for is a mechanism to open the CameraCaptureDialog, take several photos without the dialog closing until all the photo controls have images.

I am trying to implement this, but I don't see a way to get the CameraCaptureDialog to capture and save several photos at once. As far as I can tell it is not possible, because when the dialog shows on my HTC Touch Diamond, I only have the options to "Accept the photo" (arrow icon), "Capture again" (camera icon) or "cancel and close dialog" (dustbin icon). And when I click the arrow to accept it always closes the dialog box.

So does anyone know of a way of capturing and saving more than one image at a time using CameraCaptureDialog?

I then thought of trying to open the CameraCaptureDialog multiple times as a work around. So as soon as the first image is saved the dialog is immediately opened again to capture the second image. Here is my code showing my attempt at a workaround:

public partial class MPhotoControl : UserControl
{
    public static IEnumerable<MPhotoControl> PhotoControls;

    ...

    private void CaptureMultiplePhotos()
    {
        foreach (MPhotoControl photo in PhotoControls)
        {               
            using (CameraCaptureDialog cameraDialog = new CameraCaptureDialog())
            {
                if (cameraDialog.ShowDialog() != DialogResult.OK)
                {
                    break;
                }
                photo.CapturePhoto(cameraDialog.FileName);
            }
        }
    }
}

The problem with this is that the CameraCaptureDialog still only opens once and the subsequent call to the ShowDialog method simply returns DialogResult.Cancel. So, does anyone know why this workaround does not work and if it is possible to get the dialog to immediately re-open once the previous captured image has been saved?

BruceHill
  • 6,954
  • 8
  • 62
  • 114
  • It's been a long time since I developed with the CameraCaptureDialog or even WM. What happens if you swap the using and foreach? – Josh C. Oct 16 '12 at 14:51
  • Hi Josh. I originally did have one CameraCaptureDialog, defined as a static member, rather than creating a new one in the loop, but this also returned DialogResult.Cancel on the second call to the ShowDialog method. – BruceHill Oct 16 '12 at 15:18
  • This is triggering some old memories... Is there an initialization method? – Josh C. Oct 16 '12 at 15:23
  • AFAIK there is only one instance allowed for CameraCaptureDialog, that is why you cannot have multiple instances. The same is thrue for most Windows Mobile applications. - To overcome your problem, you cannot use the CameraCaptureDialog class. You may create a new process for the Camera application and wait until the Camera app has been closed (minimized). Before starting the camera process, make a snapshot of the image dir to later know, which images have been added. – josef Oct 17 '12 at 06:32
  • To run the camera as new process use "pimg.exe -camerakey" – josef Oct 17 '12 at 08:08
  • Thanks, Josef, for your comments. I've determined that this does indeed have to do with only one instance at a time being able to use the camera. I found that if I do a `Thread.Sleep` for about 3 seconds before the call to `ShowDialog` method that it then works. Clearly CameraCaptureDialog needs time to close before it can be opened again. The call to `Thread.Sleep` does mean that there is about a 4 to 5 second delay between taking one photo and being able to take the next. But at least it works. If this is not adequate for the client we will look at using the approach given in your answer. – BruceHill Oct 17 '12 at 13:24

1 Answers1

1

Please look here: http://www.hjgode.de/wp/2012/10/17/windows-mobile-cameracapturedialog-alternative/

I am unable to attach any code or binaries here, so I did a new blog post.

The code start the camera app, waits for its close-down and presents you with a list of new photos.

Code is not yet perfect but a starting point.

josef
  • 5,951
  • 1
  • 13
  • 24
  • Thanks, Josef. I was just speaking yesterday with a colleague of mine about a solution along these lines. This definitely will be a good starting point... I will take a look at it. Thanks. – BruceHill Oct 17 '12 at 13:14
  • Glad to be of help. Kind regards. ~Josef – josef Oct 17 '12 at 16:47