如何在 windows phone 8.1 中使用 MediaCapture 设置最大分辨率?
How to set maximum resolution with MediaCapture in windows phone 8.1?
我正在研究 windows phone 8.1(RT) 我使用 MediaCapture 拍照(请记住,对预览要拍摄的照片不感兴趣)。
我使用了下面的代码,但是图片的质量很糟糕,在拍摄的图片中只能看到照亮的部分。
private static async Task<DeviceInformation> GetCameraID(Windows.Devices.Enumeration.Panel desiredCamera)
{
// get available devices for capturing pictures
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));
}
public async Task takeAPicture()
{
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
});
var maxResolution = captureManager.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo).Aggregate((i1, i2) => (i1 as VideoEncodingProperties).Width > (i2 as VideoEncodingProperties).Width ? i1 : i2);
await captureManager.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, maxResolution);
StorageFile photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync("myFirstPhoto.jpg", CreationCollisionOption.GenerateUniqueName);
//take a photo with choosen Encoding
await captureManager.CapturePhotoToStorageFileAsync(ImageEncodingProperties.CreateJpeg(), photoFile);
captureManager.Dispose();
}
感谢您的帮助。
您似乎正在配置 MediaCapture 以提供 "preview-quality" 照片。改为这样做:
await captureManager.InitializeAsync(new MediaCaptureInitializationSettings
{
StreamingCaptureMode = StreamingCaptureMode.Video,
PhotoCaptureSource = PhotoCaptureSource.Photo, // I believe your bug was here
AudioDeviceId = string.Empty,
VideoDeviceId = cameraID.Id
});
或者实际上,只需尝试使用大多数这些属性的默认值,并且只设置 VideoDeviceId 以选择摄像机。它应该有助于缩小问题范围。
至于设置更高的照片捕获分辨率,这样的方法可能有效:
private async Task SetPhotoResolution()
{
var resolutions = _captureManager.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo).Select(x => x as VideoEncodingProperties);
var maxRes = resolutions.OrderByDescending(x => x.Height * x.Width).FirstOrDefault();
await _captureManager.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, maxRes);
}
请确保照片分辨率的纵横比与预览分辨率的纵横比相匹配,否则在某些 phone 的边缘附近可能会出现条纹。
此外,我测试的 phone 仅返回 NV12 VideoEncodingProperties
用于 MediaStreamType.Photo
流上的 GetAvailableMediaStreamProperties
调用。您可能需要在不同的设备上处理也包含 ImageEncodingProperties 的枚举。
我正在研究 windows phone 8.1(RT) 我使用 MediaCapture 拍照(请记住,对预览要拍摄的照片不感兴趣)。 我使用了下面的代码,但是图片的质量很糟糕,在拍摄的图片中只能看到照亮的部分。
private static async Task<DeviceInformation> GetCameraID(Windows.Devices.Enumeration.Panel desiredCamera)
{
// get available devices for capturing pictures
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));
}
public async Task takeAPicture()
{
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
});
var maxResolution = captureManager.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo).Aggregate((i1, i2) => (i1 as VideoEncodingProperties).Width > (i2 as VideoEncodingProperties).Width ? i1 : i2);
await captureManager.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, maxResolution);
StorageFile photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync("myFirstPhoto.jpg", CreationCollisionOption.GenerateUniqueName);
//take a photo with choosen Encoding
await captureManager.CapturePhotoToStorageFileAsync(ImageEncodingProperties.CreateJpeg(), photoFile);
captureManager.Dispose();
}
感谢您的帮助。
您似乎正在配置 MediaCapture 以提供 "preview-quality" 照片。改为这样做:
await captureManager.InitializeAsync(new MediaCaptureInitializationSettings
{
StreamingCaptureMode = StreamingCaptureMode.Video,
PhotoCaptureSource = PhotoCaptureSource.Photo, // I believe your bug was here
AudioDeviceId = string.Empty,
VideoDeviceId = cameraID.Id
});
或者实际上,只需尝试使用大多数这些属性的默认值,并且只设置 VideoDeviceId 以选择摄像机。它应该有助于缩小问题范围。
至于设置更高的照片捕获分辨率,这样的方法可能有效:
private async Task SetPhotoResolution()
{
var resolutions = _captureManager.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo).Select(x => x as VideoEncodingProperties);
var maxRes = resolutions.OrderByDescending(x => x.Height * x.Width).FirstOrDefault();
await _captureManager.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, maxRes);
}
请确保照片分辨率的纵横比与预览分辨率的纵横比相匹配,否则在某些 phone 的边缘附近可能会出现条纹。
此外,我测试的 phone 仅返回 NV12 VideoEncodingProperties
用于 MediaStreamType.Photo
流上的 GetAvailableMediaStreamProperties
调用。您可能需要在不同的设备上处理也包含 ImageEncodingProperties 的枚举。