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

設定ページ.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 構造体のコレクションです。各 Size は、Height プロパティと Width プロパティを指定します。ピクセル数 = 高さ x 幅

次に、1024 で適切に割って、キロ ピクセルまたはメガ ピクセルを取得します。

于 2012-07-25T09:40:00.330 に答える