我正在使用wieslawsoltes/PaZ库来对程序中的某些图像进行平移和缩放。如果图像处于原始位置,则效果很好,但是每当我旋转然后进行平移时,图像就会在查看器中消失。
我不知道这是否是库问题,因此我认为我的代码中存在一些问题。
XAML:
<paz:ZoomBorder Name="zoomBorder" Stretch="None" ZoomSpeed="1.2"
Background="Gray" ClipToBounds="True" Focusable="True"
VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
Grid.Row="4" Grid.Column="1">
<Image Source="{Binding SelectedImageToDisplay ,IsAsync=True}" Stretch="UniformToFill">
<Image.LayoutTransform>
<TransformGroup>
<ScaleTransform ScaleX="{Binding ScaleX, UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" ScaleY="{Binding ScaleY, UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"/>
<RotateTransform Angle="{Binding RotationAngle, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>
</TransformGroup>
</Image.LayoutTransform>
</Image>
</paz:ZoomBorder>
旋转:
private async Task RotationEvent(string direction)
{
if (SelectedImageToDisplay == null) return;
switch (direction)
{
case "LEFT":
await Task.Run(() =>
{
RotationAngle = RotationAngle + -90;
});
break;
case "RIGHT":
await Task.Run(() =>
{
RotationAngle = RotationAngle + 90;
});
break;
case "FLIP":
await Task.Run(() =>
{
if (ScaleX == -1)
{
ScaleX = 1;
}
else
{
ScaleX = -1;
}
});
break;
default:
break;
}
}
图像显示:
SelectedImageToDisplay = File.ReadAllBytes(SelectedImageItem.IMG_FULLPATH);
ScaleX = 1;
ScaleY = 1;
Scale X和Y的默认值均为1。
我还有另一种解决方法,但是创建另一个文件只是在旋转版本中显示很麻烦。我的某些程序用户正在使用速度较慢的PC。
希望您能帮助我!谢谢。