/// <summary> /// 事件:鼠标点击后事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Slider_PreviewMouseUp(object sender, MouseButtonEventArgs e) { var vm = DataContext as MainViewModel; var value = (int)(sender as Slider).Value; // 计时开始 vm._watch = Stopwatch.StartNew(); CVAlgorithms.CvpBlur(OldBmpInfo.data, vm.CurrBmp.Width, vm.CurrBmp.Height, OldBmpInfo.step, value, value, ref CurrImgInfo); byte[] imagePixels = new byte[CurrImgInfo.size]; Marshal.Copy(CurrImgInfo.data, imagePixels, 0, CurrImgInfo.size); vm.CurrBitmapImage = ImageEx.ByteToBitmapImage(imagePixels); // 释放内存 CVAlgorithms.ReleaseMemUseFree(CurrImgInfo.data); // 计时结束 vm._watch.Stop(); vm.StatusText = "Execution time: " + vm._watch.ElapsedMilliseconds + " ms."; }
/// <summary> /// 取消按钮单击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Btn_cancel_Click(object sender, RoutedEventArgs e) { var vm = DataContext as MainViewModel; // 计时开始 vm._watch = Stopwatch.StartNew(); // 恢复最初图像状态,此处调用0内核blur函数跳过,实现过程看CvpBlur函数实现 CVAlgorithms.CvpBlur(OldBmpInfo.data, vm.CurrBmp.Width, vm.CurrBmp.Height, OldBmpInfo.step, 0, 0, ref CurrImgInfo); byte[] imagePixels = new byte[CurrImgInfo.size]; Marshal.Copy(CurrImgInfo.data, imagePixels, 0, CurrImgInfo.size); vm.CurrBitmapImage = ImageEx.ByteToBitmapImage(imagePixels); // 释放内存 CVAlgorithms.ReleaseMemUseFree(CurrImgInfo.data); // 计时结束 vm._watch.Stop(); vm.StatusText = "Execution time: " + vm._watch.ElapsedMilliseconds + " ms."; Close(); }