我正在尝试将视频投影方向与手机的方向相匹配,但我在实施此解决方案时遇到问题。我的xaml页面设置为PortraitOrLandscape,我希望无论手机的方向如何,视频都可以正面朝上。在将方向更改if语句添加到onOrentationChanged事件之前,会出现以下情况
电话:左转,Videobrush:正面朝上
手机:人像,视频,顺时针旋转-90
电话:右侧,Videobrush,顺时针旋转-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语句后,视频播放方向变得更加疯狂。我究竟做错了什么?无论电话的方向如何,我都希望将视频投影正面朝上。
答案 0 :(得分: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;
}
}
很适合我。