Chapter 21. Capturing Images and Video with the Camera

,

In This Chapter

Image Capturing image stills with the PhotoCamera

Image Displaying video with the PhotoCamera

Image Extending the camera experience with lenses

Image Controlling the camera’s flash and autofocus, and resolution of captured images

Image Saving images to the media library and linking to them from thumbnails stored in isolated storage

Image Capturing audio and video with the CaptureSource class

Image Leveraging the hardware shutter button


The camera has become an essential component of all mobile phones. Indeed, the manufacturing requirements for Windows Phone devices require them to have a camera with at least a 5 megapixel capability and an LED flash.

Most of the first-generation Windows Phone devices, however, did not have great cameras. New phones that have arrived since Windows Phone 7.5 (mango) have seen their cameras much improved, and mango brought with it programmatic access to both front- and rear-facing cameras, enabling scenarios such as video chat, image recognition, and augmented reality.

You saw in Chapter 14, “Leveraging Built-In Apps via Launchers and Choosers,” how the CameraCaptureTask chooser can be used to launch the Windows Phone Camera app, allowing the user to take a photo and have it returned to your app. Although convenient in some scenarios, the CameraCaptureTask limits the capabilities of the capture process to that of the built-in camera app, which supports only photos and not video capture. By using the direct access camera APIs on the phone, you can control the camera directly from your app to capture both photos and video. The APIs allow you to control many aspects of the camera, including the flash, the hardware shutter button, and the autofocus mechanism.

The Windows Phone SDK includes two distinct APIs for the camera. The first is Windows Phone specific and centers on the Microsoft.Devices.PhotoCamera class. The second is the Silverlight webcam API.

The main difference between the webcam API and the PhotoCamera class is that the PhotoCamera allows you to make the camera perform autofocus, and to set the camera’s flash mode, which the webcam API cannot.

Conversely, the webcam API allows you to capture video with audio and save it to isolated storage. The webcam API is platform agnostic, and code that uses the webcam API can also be used in Silverlight desktop and browser applications.

When deciding whether to use the PhotoCamera or the webcam API, you can make your decision based on the following criteria:

Image If your app needs to take stills only, use PhotoCamera.

Image If your app needs to capture audio and video, use the webcam API.

Image If your app needs to be cross-platform and must support Silverlight for the browser, use the webcam API.

This chapter explores both approaches, beginning with PhotoCamera. You see how to capture still images and display live video using PhotoCamera, and you also look at leveraging the hardware shutter button and adding a live video effect.

The chapter then looks at the Silverlight webcam API and how to use it to capture audio and video and save it as an MP4 in isolated storage.

Finally, the chapter examines lenses, which are new to Windows Phone 8 and enable you to extend the phone’s built-in camera experience.


Note

For the camera application to function, the Windows Phone application manifest, WMAppManifest.xml, must include a capability named ID_CAP_ISV_CAMERA. Without it, the application will not function correctly.

The following capabilities element must be present in the WMAppManifest.xml file:

<Capability Name="ID_CAP_ISV_CAMERA" />

To use a device’s front-facing camera, if it exists, you must add the ID_HW_FFCCAMERA capability, as shown:

<Capability Name=" ID_HW_FFCCAMERA" />

ID_HW_FFCCAMERA is not added automatically during the Windows Phone Marketplace capabilities detection process.

If a particular camera capability is not present, an InvalidOperationException is raised when an attempt is made by your app to use the camera. Moreover, it may not be immediately apparent that the exception is due to the missing capability definition.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.237.122