C# 如何查询相机分辨率并将其添加到列表中
我只是试图查询WP7设备的相机分辨率,并将这些分辨率添加到列表选择器中,以便用户可以选择他或她想要的视频画笔分辨率。我的视频画笔显示在我的主页上,分辨率列表选择器在我的设置页面上,因此我还需要将此值从设置页面传递到主页,以便正确应用所选的分辨率。到目前为止,我有如下内容,尽管我不确定如何获得分辨率并将其添加到ListPicker,然后将此值传递到主页中使用 MainPage.xamlC# 如何查询相机分辨率并将其添加到列表中,c#,windows-phone-7,xaml,camera,C#,Windows Phone 7,Xaml,Camera,我只是试图查询WP7设备的相机分辨率,并将这些分辨率添加到列表选择器中,以便用户可以选择他或她想要的视频画笔分辨率。我的视频画笔显示在我的主页上,分辨率列表选择器在我的设置页面上,因此我还需要将此值从设置页面传递到主页,以便正确应用所选的分辨率。到目前为止,我有如下内容,尽管我不确定如何获得分辨率并将其添加到ListPicker,然后将此值传递到主页中使用 MainPage.xaml <Border x:Name="videoRectangle" Grid.Row="0" Grid.Col
<Border x:Name="videoRectangle" Grid.Row="0" Grid.ColumnSpan="2" >
<Border.Background>
<VideoBrush x:Name="viewfinderBrush">
<VideoBrush.RelativeTransform>
<CompositeTransform x:Name="viewfinderBrushTransform" CenterX=".5" CenterY=".5" Rotation="90" />
</VideoBrush.RelativeTransform>
</VideoBrush>
</Border.Background>
</Border>
MainPage.xaml.cs
#region Fields
//Declare a field of type PhotoCamera that will hold a reference to the camera
private PhotoCamera camera;
#endregion
#region Ctr
// Constructor
public MainPage()
{
InitializeComponent();
}
#endregion
#region Navigation
protected override void OnNavigatedTo(NavigationEventArgs e)
{
//if camera = null { .. } <-- is this necessary beforehand?
// Check to see if the camera is available on the device.
if ((PhotoCamera.IsCameraTypeSupported(CameraType.Primary) == true) ||
(PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing) == true))
{
// Initialize the camera, when available.
if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary))
{
// Use front-facing camera if available.
camera = new PhotoCamera(CameraType.Primary);
camera.Initialized += camera_Initialized;
viewfinderBrush.SetSource(camera);
}
else
{
// The Primary camera is not supported on the device.
this.Dispatcher.BeginInvoke(delegate()
{
// Write message.
MessageBox.Show("Primary camera is not available on this device.", "Error!", MessageBoxButton.OK);
});
}
}
else
{
// No camera is supported on the device.
//this.Dispatcher.BeginInvoke(delegate()
//{
// Write message.
MessageBox.Show("Primary camera is available on this device.", "Error!", MessageBoxButton.OK);
//});
}
base.OnNavigatedTo(e);
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
if (camera != null)
{
camera.Dispose();
camera.Initialized -= camera_Initialized;
camera = null;
}
base.OnNavigatedFrom(e);
}
#endregion
void camera_Initialized(object sender, CameraOperationCompletedEventArgs e)
{
if (e.Succeeded)
{
//var res = from resolution in camera.AvailableResolutions
// //change to best resolution on camera
// //http://msdn.microsoft.com/en-us/library/hh202951(v=VS.92).aspx
// where resolution.Width == 640
// select resolution;
//camera.Resolution = res.First();
//***apply camera resolution here!?
this.Dispatcher.BeginInvoke(delegate()
{
ShowRegularVideo();
});
}
//throw new NotImplementedException();
}
private void ShowRegularVideo()
{
videoRectangle.Width = this.ActualWidth;
videoRectangle.Height = this.ActualHeight;
}
#region Fields
//Declare a field of type PhotoCamera that will hold a reference to the camera
private PhotoCamera camera;
List<int> resolutionsList;
#endregion
#region Ctr
public Settings()
{
InitializeComponent();
}
#endregion
#region Navigation
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
GetResolutions();
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
}
#endregion
private void GetResolutions()
{
resolutionsList = new List<int>();
//var res = from resolution in camera.AvailableResolutions
// //change to best resolution on camera
// //http://msdn.microsoft.com/en-us/library/hh202951(v=VS.92).aspx
// where resolution.Width == 640
// select resolution;
//camera.Resolution = res.First();
for (int i = 0; i < camera.AvailableResolutions.Count(); i++)
{
//resolutionsList.Add(...)
}
}
#区域字段
//声明一个PhotoCamera类型的字段,该字段将保存对摄影机的引用
私人照相机;
#端区
#区域中心
//建造师
公共主页()
{
初始化组件();
}
#端区
#区域导航
受保护的覆盖无效OnNavigatedTo(NavigationEventArgs e)
{
//如果camera=null{..}我想您是从如何:为Windows Phone创建一个基本的摄像头应用程序开始的
如果您查看Res按钮,它将显示如何更改分辨率。如果没有,请查看如何:在Windows Phone应用程序中调整捕获的图片分辨率
Camera.AvailableResolutions
分辨率是大小结构的集合。每个大小指定一个高度和宽度属性。
像素计数=高度x宽度
然后用1024进行适当的分割,得到千像素或百万像素。我已经看到了这些资源,但我的问题是如何将它们添加到listpicker中,并在主页上相应地更改此值?创建一个列表,迭代分辨率并存储它。然后将列表绑定到ListPickerRight,你给我一个f如何迭代相机分辨率,这就是我遇到问题的地方。认真吗?
#region Fields
//Declare a field of type PhotoCamera that will hold a reference to the camera
private PhotoCamera camera;
List<int> resolutionsList;
#endregion
#region Ctr
public Settings()
{
InitializeComponent();
}
#endregion
#region Navigation
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
GetResolutions();
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
}
#endregion
private void GetResolutions()
{
resolutionsList = new List<int>();
//var res = from resolution in camera.AvailableResolutions
// //change to best resolution on camera
// //http://msdn.microsoft.com/en-us/library/hh202951(v=VS.92).aspx
// where resolution.Width == 640
// select resolution;
//camera.Resolution = res.First();
for (int i = 0; i < camera.AvailableResolutions.Count(); i++)
{
//resolutionsList.Add(...)
}
}