I use the following code to take the snap using the PhotoCaptureDevice option in Windows Phone 8.
if (PhotoCaptureDevice.AvailableSensorLocations.Contains(CameraSensorLocation.Back) ||
PhotoCaptureDevice.AvailableSensorLocations.Contains(CameraSensorLocation.Front))
{
// Initialize the camera, when available.
if (PhotoCaptureDevice.AvailableSensorLocations.Contains(CameraSensorLocation.Back))
{
// Use the back camera.
System.Collections.Generic.IReadOnlyList<Windows.Foundation.Size> SupportedResolutions =
PhotoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back);
Windows.Foundation.Size res = SupportedResolutions[0];
d = await PhotoCaptureDevice.OpenAsync(CameraSensorLocation.Back, res);
}
else
{
// Otherwise, use the front camera.
System.Collections.Generic.IReadOnlyList<Windows.Foundation.Size> SupportedResolutions =
PhotoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Front);
Windows.Foundation.Size res = SupportedResolutions[0];
d = await PhotoCaptureDevice.OpenAsync(CameraSensorLocation.Front, res);
}
await d.SetPreviewResolutionAsync(new Windows.Foundation.Size(640, 480));
await d.SetCaptureResolutionAsync(new Windows.Foundation.Size(640, 480));
d.SetProperty(KnownCameraGeneralProperties.EncodeWithOrientation,
d.SensorLocation == CameraSensorLocation.Back ?
d.SensorRotationInDegrees : -d.SensorRotationInDegrees);
_device = d;
}
Finally i set this device to the Source of the Video brush. But i come from the dormant state when the application goes to this state by press and hold of back key, it shows the empty page and does not display any camera. Could you please anyone help me on this ?
Nokia has a great sample app of the many capabilities enabled in WP8’s PhotoCaptureDevice. Check it out @ http://projects.developer.nokia.com/cameraexplorer
There’s even an end-to-end example of using PhotoCaptureDevice as the VideoBrush.SetSource() right on the first page. Start from OnNavigatedTo method on MainPage.xaml.cs to see how to initialize a Camera Viewfinder with PhotoCaptureDevice @ http://projects.developer.nokia.com/cameraexplorer/browser/CameraExplorer/MainPage.xaml.cs
Here are the relevant parts:
And relevant XAML: