【问题标题】:How to set maximum resolution with MediaCapture in windows phone 8.1?如何在 windows phone 8.1 中使用 MediaCapture 设置最大分辨率?
【发布时间】:2016-01-05 21:04:50
【问题描述】:

我正在使用 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();
}

感谢您的帮助。

【问题讨论】:

  • 我在手机上玩过一次,发现最大的宽度并不意味着最大的分辨率。为什么不列举可用的宽度/高度并选择能产生最大乘法结果的组合(宽度*高度)?

标签: c# windows-runtime windows-phone-8.1


【解决方案1】:

您似乎将 MediaCapture 配置为为您提供“预览质量”的照片。改为这样做:

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);
}

请确保照片分辨率的纵横比与预览分辨率的纵横比相匹配,否则您可能会在某些手机的边缘附近出现一些条纹。

另外,我测试过的手机只为MediaStreamType.Photo 流上的GetAvailableMediaStreamProperties 调用返回了NV12 VideoEncodingProperties。您可能需要在不同的设备上处理还包含 ImageEncodingProperties 的枚举。

【讨论】:

  • 尝试了代码,但无法获得 PhotoEncodingProperties 或类似内容的任何引用,尝试了 VideoEncoding 属性以及您建议的更改,但照片只是带有白色带的深色图像。看不到任何东西
  • 抱歉,在您检查答案之前,我的编辑似乎没有及时收到。它应该很快就会出现。你在什么手机上运行这个?您有机会将示例图片上传到 imgur.com 吗?您是否在设备上尝试过不同的摄像头(正面与背面)?
  • 我使用的是 lumia 730,并在添加 PhotoCaptureSource = PhotoCaptureSource.Photo 时尝试了两个相机(正面和背面)。当我使用 VideoPreview 时。我已上传代码here takePicBtn_Click 方法中的注释行是您的建议答案。
  • 我很乐意提供帮助,但我无法访问您发布的代码。
  • here 感到抱歉。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-07-31
  • 1970-01-01
  • 1970-01-01
  • 2014-11-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多