Writing a Windows Phone 7.5 Camera Application

Overview

Windows
Phone Mango, the latest released version of the Windows
Phone operating system now allows access to the camera programmatically.
This means that application developers can now leverage the built-in camera on
these devices in their applications. In this article, we will walk through how to
build a simple Windows Phone Mango Camera application.

Camera Basics

To start with, we need to understand a few camera basics on
Windows Phone devices.

You can build a camera application that can capture still photos.

You can query device camera capabilities (where there are
multiple cameras on the device (front and/or rear), where it has flash, etc.).

You can get raw camera frames and process them yourself
(encode/decode).

You can programmatically set flash and focus when taking a photo.

You can change the resolution of the photo.

You can continue using the hardware button for the camera shutter
to capture a photo and for auto-focus when taking shots outside your
application.

A camera need not be present (for example, front facing camera
was not a part of the original devices). Your application would need to handle
that condition gracefully.

To allow your application to have access to the camera
capability, you need to specify ID_CAP_ISV_CAMERA in your application manifest
file.

To allow your application to have access to a front facing camera
(if one exists), you need to specify ID_HW_FRONTCAMERA in your application
manifest file.

Besides the camera APIs, you also have access to other
Windows Phone APIs, which would allow an application to save captured photos
into the media library, and to extend the built-in photo application and
Pictures Hub.

Hands-On

We will now create a Windows Phone camera application. Fire
off Visual Studio
and create a new Windows Phone application project titled WPCameraDemo.

Now we can compile and execute our first Windows Phone
Camera application.

Note that in the emulator, there is no support for a virtual
camera (the application will execute but you can't see anything) so you are
better off trying this on your Windows Phone.

If you are having issues following along, you can download
the sample code for the exercise below.

Summary

In this article, we learned the basics about Windows Phone
camera and how to create a Windows Phone application, which utilizes the camera
through APIs. I hope you have found this information useful.

About the Author

Vipul Vipul Patel

Vipul Patel is a Software Engineer currently working at Microsoft Corporation, working in the Office Communications Group and has worked in the .NET team earlier in the Base Class libraries and the Debugging and Profiling team. He can be reached at vipul_d_patel@hotmail.com