如何获得可访问的相机分辨率?
How to get accessible camera resolutions?
我想问一下,如何在 Windows Phone 8.1 应用程序(对于 silverlight 和 WinRT)中获得所有可用的相机分辨率。我想使用:
Windows.Phone.Media.Capture.PhotoCaptureDevice.GetAvailableCaptureResolutions(
Windows.Phone.Media.Capture.CameraSensorLocation.Back);
但我收到消息称命名空间 Windows.Phone.Media.Capture 已过时,可能不受下一版本 Windows Phone 的支持,从 Windows Phone 开始蓝色,我应该改用 Windows.Media.Capture。但是Windows.Media.Capture不允许我获得可访问的相机分辨率,所以我想问一下,如何解决这个问题。
谢谢。
可以这样做:
首先让我们定义获取设备ID的方法,它将用于拍照:
private static async Task<DeviceInformation> GetCameraID(Windows.Devices.Enumeration.Panel desiredCamera)
{
DeviceInformation deviceID = (await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture))
.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == desiredCamera);
if (deviceID != null) return deviceID;
else throw new Exception(string.Format("Camera of type {0} doesn't exist.", desiredCamera));
}
然后在我们初始化相机后 - 我们可以像这样读取分辨率:
private async void InitCameraBtn_Click(object sender, RoutedEventArgs e)
{
var cameraID = await GetCameraID(Windows.Devices.Enumeration.Panel.Back);
captureManager = new MediaCapture();
await captureManager.InitializeAsync(new MediaCaptureInitializationSettings
{
StreamingCaptureMode = StreamingCaptureMode.Video,
PhotoCaptureSource = PhotoCaptureSource.VideoPreview,
AudioDeviceId = string.Empty,
VideoDeviceId = cameraID.Id
});
// Get resolutions
var resolutions = captureManager.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo).Select(x => x as VideoEncodingProperties).ToList();
// get width and height:
uint width = resolutions[0].Width;
uint height = resolutions[0].Height;
}
我想问一下,如何在 Windows Phone 8.1 应用程序(对于 silverlight 和 WinRT)中获得所有可用的相机分辨率。我想使用:
Windows.Phone.Media.Capture.PhotoCaptureDevice.GetAvailableCaptureResolutions(
Windows.Phone.Media.Capture.CameraSensorLocation.Back);
但我收到消息称命名空间 Windows.Phone.Media.Capture 已过时,可能不受下一版本 Windows Phone 的支持,从 Windows Phone 开始蓝色,我应该改用 Windows.Media.Capture。但是Windows.Media.Capture不允许我获得可访问的相机分辨率,所以我想问一下,如何解决这个问题。
谢谢。
可以这样做:
首先让我们定义获取设备ID的方法,它将用于拍照:
private static async Task<DeviceInformation> GetCameraID(Windows.Devices.Enumeration.Panel desiredCamera)
{
DeviceInformation deviceID = (await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture))
.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == desiredCamera);
if (deviceID != null) return deviceID;
else throw new Exception(string.Format("Camera of type {0} doesn't exist.", desiredCamera));
}
然后在我们初始化相机后 - 我们可以像这样读取分辨率:
private async void InitCameraBtn_Click(object sender, RoutedEventArgs e)
{
var cameraID = await GetCameraID(Windows.Devices.Enumeration.Panel.Back);
captureManager = new MediaCapture();
await captureManager.InitializeAsync(new MediaCaptureInitializationSettings
{
StreamingCaptureMode = StreamingCaptureMode.Video,
PhotoCaptureSource = PhotoCaptureSource.VideoPreview,
AudioDeviceId = string.Empty,
VideoDeviceId = cameraID.Id
});
// Get resolutions
var resolutions = captureManager.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo).Select(x => x as VideoEncodingProperties).ToList();
// get width and height:
uint width = resolutions[0].Width;
uint height = resolutions[0].Height;
}