[UWP] [C#]如何在C#中创建和旋转图像? [英] [UWP][C#]How to CREATE and ROTATE, MOVE Image in C#?
本文介绍了[UWP] [C#]如何在C#中创建和旋转图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好!
如何创建ImageControl并顺时针旋转90度并向上或向下移动?
How to create ImageControl and rotate it 90 degrees clockwise and move it up or down?
谢谢你好!
推荐答案
嗨Nguyen_Thanh_Liem,
Hi Nguyen_Thanh_Liem,
你可以使用 RenderTransForm 来旋转图片xaml,图像将旋转一度。然后使用 ManipulationDelta 事件
在操作期间观察输入设备改变位置以实现上下移动的效果。您可以尝试以下代码。
You can use a RenderTransForm to rotate an Image in the xaml, the Image will rotate a degree. Then using the ManipulationDelta event to observe input device changes position during a manipulation to implement the effect that move up and down. You can try the following code.
在Xaml中,
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid Name="MyGrid" Width="100" Height="100">
<Image HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Source="Assets\picture.png" ManipulationMode="All" RenderTransformOrigin="0.5,0.5">
<Image.RenderTransform>
<RotateTransform Angle="90"/>
</Image.RenderTransform>
</Image>
</Grid>
</Grid>
在后面的c#代码中,
public sealed partial class MainPage : Page
{
private TranslateTransform dragTranslation;
public MainPage()
{
this.InitializeComponent();
MyGrid.ManipulationDelta += MyGrid_ManipulationDelta;
// New translation transform populated in
// the ManipulationDelta handler.
dragTranslation = new TranslateTransform();
// Apply the translation to the Grid.
MyGrid.RenderTransform= this.dragTranslation;
}
private void MyGrid_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
// Move the Image(Grid).
dragTranslation.X += e.Delta.Translation.X;
dragTranslation.Y += e.Delta.Translation.Y;
}
}
祝你好运,
Breeze
这篇关于[UWP] [C#]如何在C#中创建和旋转图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文