WP8.1RT:从 mediacapture C# 获取的自定义分辨率图像
WP8.1RT: Custom resolution image taken from mediacapture C#
在网站上浏览以找到解决方案后,我遇到了一些困难。我遇到的问题是我正在尝试使用从 url (download 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 的图像,这真的可以吗?
只有当您的相机支持时,您才可以使用 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++;
}
}
Select你要的那个:
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< VideoEncodingProperties > 。这是因为我只想要数字。
在第二种方法中,我使用了 IReadOnlyList< IMediaEncodingProperties >。这是因为只需要应用包含所需分辨率的 VideoEncodingProperties。并非每个 IMediaEncodingProperties 都包含分辨率信息。
在网站上浏览以找到解决方案后,我遇到了一些困难。我遇到的问题是我正在尝试使用从 url (download 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 的图像,这真的可以吗?
只有当您的相机支持时,您才可以使用 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++;
}
}
Select你要的那个:
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< VideoEncodingProperties > 。这是因为我只想要数字。
在第二种方法中,我使用了 IReadOnlyList< IMediaEncodingProperties >。这是因为只需要应用包含所需分辨率的 VideoEncodingProperties。并非每个 IMediaEncodingProperties 都包含分辨率信息。