Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法在acer平板电脑上的xaml应用程序中获取相机的最大分辨率_C#_Windows 8_Microsoft Metro - Fatal编程技术网

C# 无法在acer平板电脑上的xaml应用程序中获取相机的最大分辨率

C# 无法在acer平板电脑上的xaml应用程序中获取相机的最大分辨率,c#,windows-8,microsoft-metro,C#,Windows 8,Microsoft Metro,这段代码的目的是为cam获得最佳(最大)分辨率,然后为其拍照,但它只为VGA拍照,而cam的分辨率为800万像素。请纠正我这个代码有什么问题。谢谢 <Page x:Class="win8appbycrs.BlankPage2" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local=

这段代码的目的是为cam获得最佳(最大)分辨率,然后为其拍照,但它只为VGA拍照,而cam的分辨率为800万像素。请纠正我这个代码有什么问题。谢谢

<Page
x:Class="win8appbycrs.BlankPage2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:win8appbycrs"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
    <Image x:Name="image" HorizontalAlignment="Left" Height="424" Margin="254,45,0,0" VerticalAlignment="Top" Width="619"/>
    <Button Content="Set" HorizontalAlignment="Left" Margin="978,293,0,0" VerticalAlignment="Top" Click="Button_Click"/>
    <CaptureElement x:Name="ce" HorizontalAlignment="Left" Height="268" Margin="97,490,0,0" VerticalAlignment="Top" Width="421" Stretch="Fill"/>
    <ComboBox x:Name="ComboBox1" HorizontalAlignment="Left" Margin="659,474,0,0" VerticalAlignment="Top" Width="120"/>
    <Button Content="Capture" HorizontalAlignment="Left" Margin="840,499,0,0" VerticalAlignment="Top" Click="Button_Click_1"/>
    <Image x:Name="Img" HorizontalAlignment="Left" Height="225" Margin="254,133,0,0" VerticalAlignment="Top" Width="356"/>
</Grid>

C#代码:

publicblankpage2()
{
初始化组件();
mediaCaptureMgr=新的MediaCapture();
StartPreview();
}
/// 
///当此页面即将显示在框架中时调用。
/// 
///描述如何到达此页面的事件数据。参数
///属性通常用于配置页面。
受保护的覆盖无效OnNavigatedTo(NavigationEventArgs e)
{
}
专用异步无效按钮\u单击(对象发送方,路由目标)
{
int max_res=0;
选定的整数=0;
斯加梅拉纳姆;
var interfaces=wait Windows.Devices.Enumeration.DeviceInformation.findalsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture);
foreach(接口中的设备信息设备接口)
{
sCameraName=deviceInterface.Name.ToString();
MediaCaptureInitializationSettings captureInitSettings=新建Windows.Media.Capture.MediaCaptureInitializationSettings();
captureInitSettings.VideoDeviceId=deviceInterface.Id;
captureInitSettings.PhotoCaptureSource=PhotoCaptureSource.VideoPreview;
//枚举每个摄像头的支持配置
MediaCapture mediaCaptureMgr=新的Windows.Media.Capture.MediaCapture();
等待mediaCaptureMgr.InitializeAsync(captureInitSettings);
//System.Collections.Generic.IReadOnlyList res=mediaCaptureMgr.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoRecord);
res=mediaCaptureMgr.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview);
//如果没有可用的设置,请退出
如果(res.Count<1)返回;
//列出设备的设置组合数
字符串scont=sCameraName+“:”+res.Count.ToString();
//ComboBox1.Items.Add(Scont);
//列出不同的格式设置
对于(int i=0;i最大分辨率)
{
分辨率max=vp;
最大分辨率=(int)vp.Width;
选定=i;
}
}
}
setres(选定);
}
异步void StartPreview()
{
尝试
{
等待mediaCaptureMgr.InitializeAsync();
ce.Source=mediaCaptureMgr;
等待mediaCaptureMgr.StartPreviewSync();
}
捕获(例外情况除外)
{
mediaCaptureMgr=null;
GC.Collect();
}
}
专用异步void setres(int-maxres)
{
等待mediaCaptureMgr.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview,res[maxres]);
}
专用异步无效按钮\u单击\u 1(对象发送方,路由目标)
{
var captureSettings=新的ImageEncodingProperties();
captureSettings.Height=分辨率最大高度;
captureSettings.Width=分辨率最大宽度;
captureSettings.Subtype=“Jpeg”;
//需要文档库功能
var folder=ApplicationData.Current.RoamingFolder;
var folder1=KnownFolders.PicturesLibrary;
var file=await folder.CreateFileAsync(@“Captured.jpg”、Windows.Storage.CreationCollisionOption.GenerateUniqueName);
等待mediaCaptureMgr.CapturePhotoToStorageFileAsync(captureSettings,file);
Img.Source=新的位图图像(新的Uri(@file.Path));
wait file.copyanc(folder1);
}

这里只是猜测一下-不要使用
视频预览
来获得分辨率,你应该尝试使用
照片

//res = mediaCaptureMgr.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview);
res = mediaCaptureMgr.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo);

我也试过了,但不起作用,即使cameracapturecui提供了完美的分辨率。
//res = mediaCaptureMgr.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview);
res = mediaCaptureMgr.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo);