5

我正在尝试将视频画笔方向与手机的方向相匹配,但我在实施此解决方案时遇到了问题。我的 xaml 页面设置为 PortraitOrLandscape,无论手机的方向如何,我都希望视频画笔正面朝上。在 onOrentationChanged 事件中添加方向改变 if 语句之前,出现以下情况

电话:横向左侧,视频画笔:右侧向上

电话:人像,视频画笔,顺时针旋转 -90

电话:横向右侧,视频画笔,顺时针旋转 -180

XAML

<Rectangle x:Name="videoRectangle" Margin="0,0,0,0">
            <Rectangle.Fill>
                <VideoBrush x:Name="viewfinderBrush" AlignmentX="Left" AlignmentY="Top" Stretch="UniformToFill">
                    <VideoBrush.RelativeTransform>
                        <CompositeTransform x:Name="viewfinderTransform" 
                                            CenterX="0.5" CenterY="0.5"/>
                    </VideoBrush.RelativeTransform>
                </VideoBrush>                    
            </Rectangle.Fill>
        </Rectangle>

XAML.CS

protected override void OnOrientationChanged(OrientationChangedEventArgs e)
    {
        base.OnOrientationChanged(e);

        if (e.Orientation == PageOrientation.LandscapeLeft)
        {                //do nothing
                         //The videobrush orientation is currently right side up
        }
        if (e.Orientation == PageOrientation.Portrait)
        {
            //the videobrush is currently rotated 90 degrees counter clockwise
            this.viewfinderTransform.Rotation = this.camera.Orientation + 90.0;
        }
        if (e.Orientation == PageOrientation.LandscapeRight)
        {
            //the videobrush is currently rotated 180 degrees counter clockwise
            this.viewfinderTransform.Rotation = this.camera.Orientation + 180;
        }
    }

添加 if 语句后,画笔方向变得更加疯狂。我究竟做错了什么?无论手机的方向如何,我只想让视频画笔正面朝上。

4

1 回答 1

6

我正在使用一个简单的开关/外壳来正确旋转视频画笔:

protected override void OnOrientationChanged(OrientationChangedEventArgs e)
{
  base.OnOrientationChanged(e);
  switch (e.Orientation)
  {
    case PageOrientation.Landscape:
    case PageOrientation.LandscapeLeft:
      videoBrushTransform.Rotation = 0;
      break;
    case PageOrientation.LandscapeRight:
      videoBrushTransform.Rotation = 180;
      break;
    case PageOrientation.Portrait:
    case PageOrientation.PortraitUp:
      videoBrushTransform.Rotation = 90;
      break;
    case PageOrientation.PortraitDown:
      videoBrushTransform.Rotation = 270;
      break;
  }
}

很适合我。

于 2012-06-12T10:25:22.697 回答