WPF 实现水纹效果
鼠標滑過產生水紋,效果圖如下:
?
?
XMAL就放置了一個img標簽
?
后臺主要代碼
窗體加載:
private void Window_Loaded(object sender, RoutedEventArgs e) { Bitmap bmp = Properties.Resources.water; ww = new WaterWave(bmp); //設置顯示大小和圖片一樣 this.gInfo.Width = bmp.Width; this.gInfo.Height = bmp.Height; this.imgShow.Source = ToConvertToImageSource(bmp); ToBindTimerEvent(); }
?
計時器:
public void ToBindTimerEvent() { //創建timer 計時器 DispatcherTimer timer = new DispatcherTimer { Interval = new TimeSpan(0, 0, 0, 0, 100) }; timer.Tick += new EventHandler(timer_Tick); timer.Start(); } public void timer_Tick(object sender, EventArgs e) { Bitmap b = ww.GetFrame(); this.imgShow.Source = ToConvertToImageSource(b); }
?
鼠標移動事件:
?
private void Image_MouseMove(object sender, MouseEventArgs e) { //獲取表示二維空間內的 X 和 Y 坐標對,X、Y 為 double 類型 System.Windows.Point position = e.GetPosition(this); //轉換為System.Drawing.Point形式 System.Drawing.Point dPoint = new System.Drawing.Point(); dPoint.X = (int)position.X; dPoint.Y = (int)position.Y; ww.DropStone(dPoint); }
?
水紋的算法參考
http://dev.gameres.com/Program/Visual/2D/2DWater.htm
http://topic.csdn.net/u/20100331/16/7b52e46e-d859-4af1-921d-10a9c2bd88ff.html
?
代碼實例:
http://download.csdn.net/source/3117591
?
posted on 2018-09-25 23:55 NET未來之路 閱讀(...) 評論(...) 編輯 收藏轉載于:https://www.cnblogs.com/lonelyxmas/p/9704328.html
總結
以上是生活随笔為你收集整理的WPF 实现水纹效果的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 4g突然变2g恢复不了是不是卡坏了?
- 下一篇: 设计模式之- 外观模式(Facade P