Jason Langrage asked if it’s possible to automatically capture an image from the camera of a WM 5.0 Smartphone every 30 mins, and then to upload to a web service.

WM5.0 has three new ways of working with the camera, but unfortunately the two mechanisms easily accessible from managed code both require user input in order to capture an image.

The first new api is CameraCaptureDialog that allows an application to invoke the camera view so the user can capture stills, video or video and audio files to a store location on the device.

CameraCaptureDialog ccd = new CameraCaptureDialog();


pictureBox1.Image = new Bitmap(ccd.FileName);

The second api is SelectPictureDialog and is a step further away from the camera, providing a list of images found on the device and an option to invoke the camera to capture another.

SelectPictureDialog ssdn = new SelectPictureDialog();


pictureBox1.Image = new Bitmap(ssdn.FileName);

Both of these are useful, but can’t be used to automatically drive camera capture. The third new technique for working with the camera is through DirectShow. This is a fairly complex set of COM objects taken from the desktop equivalent and reduced to fit the device. It provides modular structure for processing video and audio data both for capture and for display. For full documentation of DirectShow on the desktop take a look here. For more specific info on DirectShow for Windows CE 5.0 take a look here.

There is a sample native app in the SDK called CameraCapture that shows how to use DShow to build a filter graph that takes the camera input, encodes it as a WMV and stores a video file. It also has a still image graph that stores a single still image as a file. It’s possible with CF 2.0 to turn the whole sample into managed code, but I couldn’t be bothered so I just converted the CameraCapture into a DLL, stripped the video bits to leave just the still image processing. Then a simple managed app with a timer fires the request every 30 seconds and uploads to a web service using Base64 encoding. Pretty straight forward really.

Anyway, if you want the code then its here:

TimedCamera.ZIP        - device camera code.

ImageUpload.zip          - web server code.

Extract the web site to your inetpub\wwwroot, right click on ImageUpload select Sharing and Security, then select the web tab and enable sharing with the default settings. Next build and run the TimedCapture code on your device. The standard code disclaimer applies.

I guess the next step is to use a socket to stream camera video from device to a desktop…