0

我只是想查询 WP7 设备的相机分辨率,并将这些分辨率添加到 ListPicker,以便用户可以选择他或她想要的视频画笔分辨率。我的 videobrush 显示在我的 MainPage 上,分辨率 ListPicker 在我的 SettingsPage 上,因此我还需要将此值从 SettingsPage 传递到 MainPage,以便正确应用所选分辨率。到目前为止,我所拥有的如下,虽然我不确定如何获取分辨率并将它们添加到 ListPicker,然后传递这个值以在 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;
    }

设置页面.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(...)
        }
    }
4

1 回答 1

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

分辨率是大小结构的集合。每个 Size 指定一个 Height 和 Width 属性。像素数 = 高 x 宽

然后用 1024 适当除以得到千像素或百万像素

于 2012-07-25T09:40:00.330 回答