使用canavas可以放大和缩小相机,而且我在方向上也有错误,它是一个Windows Phone应用程序
本文关键字:有错误 Phone 应用程序 Windows 一个 方向 放大 canavas 缩小 相机 使用 | 更新日期: 2023-09-27 18:18:31
这就是我到目前为止尝试的方向,我在 potitdown 中遇到了问题,它最多显示图像我想做的两件事是第一默认相机方向和第二次放大和缩小,然后再捕获图像
我用 XAML 编写了此代码
<Canvas x:Name="viewfinderCanvas" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,10">
<Canvas.Background>
<VideoBrush x:Name="viewfinderBrush">
<VideoBrush.RelativeTransform>
<CompositeTransform
x:Name="viewfinderTransform"
CenterX="0.5"
CenterY="0.5"
Rotation="-90" />
</VideoBrush.RelativeTransform>
</VideoBrush>
</Canvas.Background>
</Canvas>
这是针对方向 C#
protected override void OnOrientationChanged(OrientationChangedEventArgs e)
{
if (cam != null)
{
if (e.Orientation == PageOrientation.LandscapeRight)
{
landscapeRightRotation = 180;
// Rotate for LandscapeRight orientation.
viewfinderBrush.RelativeTransform =
new CompositeTransform() { CenterX = 0.5, CenterY = 0.5, Rotation = landscapeRightRotation };
}
else if (e.Orientation == PageOrientation.PortraitUp)
{
landscapeRightRotation = -90;
viewfinderBrush.RelativeTransform =
new CompositeTransform() { CenterX = 0.5, CenterY = 0.5, Rotation = landscapeRightRotation };
}
else if (e.Orientation == PageOrientation.PortraitDown)
{
landscapeRightRotation = 0;
// Rotate for LandscapeRight orientation.
viewfinderBrush.RelativeTransform =
new CompositeTransform() { CenterX = 0.5, CenterY = 0.5, Rotation = landscapeRightRotation };
}
else
{
viewfinderBrush.RelativeTransform =
new CompositeTransform() { CenterX = 0.5, CenterY = 0.5, Rotation = 0 };
}
}
viewfinderTransform.ScaleY = 0;
base.OnOrientationChanged(e);
}
我能够通过添加两件事来解决放大和缩小
RenderTransform
和Slider
但仍然面临定向问题 Xaml 已更新
<Canvas x:Name="viewfinderCanvas" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,10">
<Canvas.RenderTransform>
<ScaleTransform x:Name="zoom"/>
<!--<CompositeTransform scalex="-1"/>-->
</Canvas.RenderTransform>
<Canvas.Background>
<VideoBrush x:Name="viewfinderBrush">
<VideoBrush.RelativeTransform>
<CompositeTransform
x:Name="viewfinderTransform"
CenterX="0.5"
CenterY="0.5"
Rotation="-90" />
</VideoBrush.RelativeTransform>
</VideoBrush>
</Canvas.Background>
</Canvas>
<Slider Foreground="White" Value="1" Opacity=".3" Background="White" Visibility="Visible" Name="zoomSlider" ValueChanged="zoomSlider_ValueChanged_1" Margin="0,570,0,10" />
和用于zoomSlider_ValueChanged_1的 C#
private void zoomSlider_ValueChanged_1(object sender, RoutedPropertyChangedEventArgs<double> e)
{
try
{
zoom.ScaleX = zoomSlider.Value;
zoom.ScaleY = zoomSlider.Value;
zoom.CenterX = 10;
zoom.CenterY = 5;
}
catch (Exception)
{
}
}