Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

videobrush orientation does not match phone orientation

I am attempting to match the videobrush orientation to the orientation of the phone, but I am having issues implementing this solution. My xaml page is set to PortraitOrLandscape, and I would like for the videobrush to be right side up regardless of the phone's orientation. Before adding the orientation changing if statements to the onOrentationChanged event, the following situation is occuring

Phone: Landscape left, Videobrush: right side up

Phone: Portrait, Videobrush, rotated -90 clockwise

Phone: Landscape right, Videobrush, rotated -180 clockwise

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

And after adding the if statements, the videobrush orientation gets even crazier. What am I doing wrong? I simply would like to have the videobrush oriented right side up regardless of the phone's orientation.

like image 474
Matthew Avatar asked Apr 19 '12 01:04

Matthew


1 Answers

I'm using a simple switch/case to properly rotate the videobrush:

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

Works nicely for me.

like image 150
Sam Avatar answered Sep 23 '22 15:09

Sam