這篇文章主要給大家介紹了關於c#實現圖片的平移和旋轉的相關資料,文中通過示例代碼介紹的非常詳細,對大家學習或者使用c#具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
前言
本文主要給大家分享了關於利用c#實現圖片的平移和旋轉的相關內容,分享出來供大家參考學習,下面話不多說了,來一起看看詳細的介紹吧
方法如下
1新建文件夾,添加一個圖片
2 添加控件 兩個button控件 一個image控件 一個Canvas控件
3 代碼實現
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace WpfApplication16 { /// <summary> /// MainWindow.xaml 的交互邏輯 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void button_Click(object sender, RoutedEventArgs e) { DoubleAnimation da = new DoubleAnimation(); da.From = 0; da.To = -100; Storyboard board = new Storyboard(); Storyboard .SetTarget(da,image); Storyboard.SetTargetProperty(da,new PropertyPath(Canvas.LeftProperty)); board.Children.Add(da); board.Begin(); } private void xuanzhuan() { RotateTransform totate = new RotateTransform(); image.RenderTransform = totate; image.RenderTransformOrigin = new Point(0.5, 0.5); DoubleAnimation da = new DoubleAnimation(0, 360, new Duration(TimeSpan.FromMilliseconds(500))); Storyboard board = new Storyboard(); Storyboard.SetTarget(da, image); Storyboard.SetTargetProperty(da,new PropertyPath("RenderTransform.Angle")); da.RepeatBehavior = RepeatBehavior.Forever; da.Completed += Da_Completed; board.Children.Add(da); board.Begin(); } private void Da_Completed(object sender, EventArgs e) { } private void button1_Click(object sender, RoutedEventArgs e) { xuanzhuan(); } } }
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對神馬文庫的支持。