The orientation of the video does not match the orientation of the phone

I am trying to match the orientation of the video with the orientation of the phone, but I am having problems with this solution. My xaml page is set to PortraitOrLandscape and I would like the video to be right-side up, regardless of the orientation of the phone. Before adding orientation changes, if the instructions are in the onOrentationChanged event, the following situation occurs

Phone: Landscape on the left, Video: right up

Phone: portrait, video rotated -90 clockwise

Phone: Landscape on the right, Movie 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 if statements, the video orientation becomes even crazier. What am I doing wrong? I just would like the right side of the video to face up regardless of the orientation of the phone.

+6
source share
1 answer

I use a simple switch / case to rotate the video bus correctly:

 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 well for me.

+6
source

Source: https://habr.com/ru/post/913588/


All Articles