In the very first release of the SDK for Windows Phone 7 development, it was not possible to use the camera in the emulator. The latest version of the SDK fixes this problem.

Windows Phone 7 SDK comes with a set of Task (in the Microsoft.Phone.Tasks namespace). A task can be launched from your application in order to perform some work. Currently available tasks are:

In order to launch a task from your application, all you need to do is to instantiate the associated type and call the Show() method.

Here is a sample code which launchs the StartCameraTask and then gets the capture images in order to use it in a standard Silverlight Image control:

?View Code CSHARP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// launch the camera capture when the user touch the screen
this.MouseLeftButtonUp += (s, e) => new CameraCaptureTask().Show();
 
// this static event is raised when a task completes its job
ChooserListener.ChooserCompleted += (s, e) =>
{
    var taskEventArgs = (TaskEventArgs<PhotoResult>)e;
    var photoStream = taskEventArgs.Result.ChosenPhoto;
 
    var bitmapImage = new BitmapImage();
    bitmapImage.SetSource(photoStream);
 
    this.image.Source = bitmapImage;
};

The image is just a standard Silverlight Image control:

1
<Image x:Name="image"/>

The emulator while the task is running:

The captured image (shown once the task has completed):

If you haven’t download the tool already, go ahead and grab them ! Everything is available for free in a single download at http://developer.windowsphone.com/windows-phone-7-series/.

Hope this helps :-)

Note: even though the StartCameraTask is now working, this is not yet the case for all the tasks…