Lenses for Windows Phone 8
Applies to: Windows Phone 8 and Windows Phone Silverlight 8.1 only
In Windows Phone 8, you can create a camera app called a lens. A lens opens from the built-in camera app and launches right into a viewfinder experience to help the user capture the moment. But not all lenses stop at capturing photos. Some lenses, called rich media lenses, provide a unique experience for viewing or editing photography. Other lenses use the camera as a gateway to a different experience. For example, a bar code reader lens might use the camera to scan a bar code and then display related data from the local folder. For more info about lens design, see Lens design guidelines for Windows Phone.
What all lenses have in common is that they use lens extensibility to launch directly from the lens picker into a viewfinder experience. Lenses also use the Microsoft.Devices.PhotoCamera and/or PhotoCaptureDevice APIs to programmatically access the camera sensor. For more info, see Lens extensibility for Windows Phone 8 and Capturing photos for Windows Phone 8.
This topic contains the following sections.
When a user presses the hardware shutter button or taps Camera in the App list, the built-in camera app starts. From the app bar, the Lens button appears as shown in the following figure.
The Lens button opens the lens picker, in which a user can choose a lens for the camera. The lens picker displays a list of apps in the Windows Phone Store that support lenses. The following figure shows the lens picker, with some example lenses.
Lenses shown in the lens picker also are listed in the Store in their standard app categories. Although a lens must provide a viewfinder experience when launched from the lens button, the app can provide other experiences, too. For example, you might create a productivity app that displays a panorama control when a user starts the app from the App list, but when a user starts the app from the lens picker, they see a viewfinder.
When a user taps a lens in the lens picker, the corresponding app is launched via a deep link URI. The deep link URI targets the corresponding app and includes the string ViewfinderLaunch to indicate that the app is to be launched as a lens. Apps can use the deep link URI to recognize a lens launch.
After opening a lens, the user can tap the hardware Back button to return to the built-in camera app. This sequence is shown in the following figure.
Integration with the lens picker is enabled by lens extensibility. For more info about setting up lens extensibility, see Lens extensibility for Windows Phone 8.
The lens feature can do more than launch an app from the built-in camera. Rich media lenses incorporate data from the local folder or the web to provide a richer and deeper way of engaging with images they have captured. A rich media lens can save a JPG image to the media library to represent each rich media item that it has captured. When viewing that image from the built-in photo viewer, it’s marked with a captured by caption. Then, from the app bar, users can relaunch the rich media experience by tapping the open link. For example, the open link might allow users to modify the rich media item and save a new copy, or the open link might allow users to view the rich media item in an interesting way.
The following figure shows the captured by caption and the open link. For more info, see Rich media extensibility for Windows Phone 8.
Rich media lenses differ from a traditional camera app because they save additional information about the image in the app’s local folder. For example, if your app provides a unique editing experience, it might save a copy of the original image so that the user can “start over” with their editing. In another example, an app might use the local folder to save additional captured images that are used to create the “final” image that is saved to the media library.
To identify an image in the media library, you can obtain its file path using an extension method for the Picture class named GetPath(). To use GetPath, add a directive to Microsoft.Xna.Framework.Media.PhoneExtensions.
If a page in your rich media app displays all rich media items, enumerate the items using the file paths that your app saves in the local folder. Don’t use the media library APIs to enumerate rich media items. The user can delete images from the media library at any time; your app shouldn’t assume that a specific image will exist in the media library.
Before you create a lens app, make sure you review the lens design guidelines. Users will have expectations for how your lens should work; the guidelines help ensure that your lens provides a consistent experience for them. For more info, see Lens design guidelines for Windows Phone.
Create a lens app by performing the following steps. As with all Windows Phone apps, be sure to review the applicable certification requirements before you start a new project. For requirements related to lenses, see Additional requirements for specific app types for Windows Phone.
To create a lens app
Specify the capabilities needed to access the camera and media library. We also recommend specifying a camera requirement for your lens. For the full list of capabilities, see App capabilities and hardware requirements for Windows Phone 8. At a minimum, you’ll probably need:
ID_CAP_ISV_CAMERA – the capability required to access the front and back cameras on the phone.
ID_CAP_MEDIALIB_PHOTO – the capability required to access the media library.
Incorporate lens extensibility into your app. By registering for a lens extension, your lens app will appear in the lens picker. It’s the responsibility of your app to ensure that it opens to a viewfinder experience when launched from the lens picker. You also need to create new icons specifically for the lens picker. For more info, see Lens extensibility for Windows Phone 8.
(optional) If your lens provides a rich media experience for the images it has captured, incorporate rich media extensibility. But don’t use this type of extensibility for general photo editing (in that case, extend the edit or apps picker). By registering for a rich media extension, your app can launch a rich media experience from the open link of the built-in photo viewer. It’s the responsibility of your app to open the rich media item that corresponds with the image the user was viewing; the user should not have to reselect the image in the media library. For more info, see Rich media extensibility for Windows Phone 8.
For an example of lens app, see the Basic Lens Sample.