我正在尝试将画笔方向与手机方向相匹配,但我在实现此解决方案时遇到了问题。我的 xaml 页面设置为 PortraitOrLandscape,无论手机的方向如何,我都希望视频画笔正面朝上。在onOrentationChanged事件中加入方向改变if语句之前,出现了如下情况
手机:横向左侧,Videobrush:右侧朝上
手机:人像,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 语句后,画笔方向变得更加疯狂。我究竟做错了什么?无论手机的方向如何,我只是想让画笔正面朝上。
最佳答案
我正在使用一个简单的开关/外壳来正确旋转画笔:
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;
}
}
对我来说效果很好。
关于c# - 画笔方向与手机方向不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10220558/