2012-07-25 81 views
0

我只是試圖查詢WP7設備的相機分辨率,並將這些分辨率添加到ListPicker,以便用戶可以選擇他或她想要的視頻分辨率。我的視頻畫面顯示在我的MainPage上,分辨率ListPicker位於我的SettingsPage上,所以我還需要將此值從SettingsPage傳遞到MainPage,以便正確應用所選分辨率。到目前爲止,我擁有如下內容,儘管我不確定如何獲取分辨率並將它們添加到ListPicker,然後將此值傳遞給MainPage中使用?如何查詢相機分辨率及其列表

MainPage.xaml中

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

SettingsPage.xaml

<toolkit:ListPicker x:Name="ResolutionListPicker" Header="Resolutions" Grid.Row="3" Grid.ColumnSpan="2"            
             SelectedIndex="{Binding}" 
             SelectionChanged="ResolutionListPicker_SelectionChanged"/> 

SettingsPage.xaml.cs

#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(...) 
     } 
    } 

回答

0

我想你開始如何創建Windows Phone的一個基本攝像機應用 http://msdn.microsoft.com/en-us/library/hh202956(v=vs.92).aspx

,如果你看一下RES按鈕,它表明你如何改變分辨率。如果不是看看如何:調整拍攝畫面分辨率在應用程序中的Windows Phone http://msdn.microsoft.com/en-us/library/hh202951(v=vs.92).aspx

Camera.AvailableResolutions http://msdn.microsoft.com/en-us/library/microsoft.devices.camera.availableresolutions(v=vs.92).aspx

決議是尺寸結構的集合。每個大小指定一個高度和寬度屬性。 Pixelcount =高x寬

然後你把它與1024

+0

適當地將獲得千像素或百萬像素我見過這些資源,但我的問題是真的如何將它們添加到listpicker也在MainPage中相應地更改此值? – Matthew 2012-07-26 17:19:30

+0

創建一個列表,迭代分辨率並存儲它..然後將列表綁定到listpicker – 2012-07-26 19:45:25

+0

可能你給我一個如何迭代攝像機分辨率的例子,那就是我遇到問題的地方。 – Matthew 2012-07-27 01:22:58