WP8.1RT:从mediacapture C#中获取的自定义分辨率图像

时间:2015-07-18 15:26:55

标签: c# xaml windows-phone-8.1 windows-store-apps

我在浏览网站后找到解决方案时遇到了一些困难。我遇到的问题是我正在尝试使用此url(下载here)中的mediacapture来捕获图像。

我已经在SO中发现了一些处理分辨率的线程,但他们正在做的是使用默认分辨率如下

3024*4992.......4:3
1936*2592...162:121
1536*2048.......4:3
480*640..........4:3
3024*5376.....16:9
1728*3072.....16:9
1456*2592...162:91

(由this建议)

然而我想要的是捕获800x600分辨率的图像,这真的有可能吗?

1 个答案:

答案 0 :(得分:2)

只有在相机支持时才能使用800x600。例如我的相机没有。

查找可用的解决方案:

uint[] x_res; // available horizontal resolutions
uint[] y_res; // available vertical resolutions
uint resolutionwidth; //used horizontal resolution
uint resolutionheight; //used vertical resolution

private void get_res_button_click(object sender, RoutedEventArgs e)
{
    resolution_listbox.Items.Clear();
    IEnumerable<VideoEncodingProperties> available_resolutions = captureManager.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo).Select(x => x as VideoEncodingProperties);
    int total_res = available_resolutions.Count();
    x_res = new uint[total_res];
    y_res = new uint[total_res]
    int i = 0;
    foreach (VideoEncodingProperties resolution in available_resolutions)
    {
        x_res[i] = resolution.Width;
        y_res[i] = resolution.Height;
        resolution_listbox.Items.Add(x_res[i].ToString() + "  x  " + y_res[i].ToString());
        i++;
    }
}

选择您想要的那个:

private async void resolution_listbox_selectionchanged(object sender, SelectionChangedEventArgs e)
{
    if (resolution_listbox.SelectedItem != null)
    {
        int j = resolution_listbox.SelectedIndex;
        resolutionwidth = x_res[j];
        resolutionheight = y_res[j];
    }
// And apply it:
    IReadOnlyList<IMediaEncodingProperties> resolutions = captureManager.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo);
    for (int k = 0; k < resolutions.Count; k++)
    {
        if (resolutions[k] is VideoEncodingProperties)
        {
            VideoEncodingProperties vidprops = (VideoEncodingProperties)resolutions[k];
            // check which VideoEncodingProperties contains the correct resolution
            if (vidprops.Width == resolutionwidth && vidprops.Height == resolutionheight)
            {
                await captureManager.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, resolutions[k]);
            }
        }
    }
}

注意:在第一种方法中,我使用了 IEnumerable&lt; VideoEncodingProperties&gt; 。这是因为我只想要数字。

在第二种方法中,我使用了 IReadOnlyList&lt; IMediaEncodingProperties&gt; 。这是因为只需要应用包含所需分辨率的 VideoEncodingProperties 。并非每个 IMediaEncodingProperties 都包含分辨率信息。