鼠标滑过产生水纹,效果图如下:
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