private void ApplayFilter(object sender, RoutedEventArgs e) { Button pickedFilter = sender as Button; System.Drawing.Bitmap bitmapCanvas = CanvasTool.getBitmapFromCanvas(); System.Drawing.Bitmap afterFilter; System.Windows.Controls.Image MyImg = new System.Windows.Controls.Image(); IntPtr hBitmap; FilterBase filter; switch (pickedFilter.Name) { case "EdgeDetection_Btn": filter = new EdgeDetectionFilter(); afterFilter = bitmapCanvas.ConvolutionFilter(filter); hBitmap = afterFilter.GetHbitmap(); MyImg.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); main_canvas.Children.Clear(); main_canvas.Children.Add(MyImg); break; case "GaussianBlur_Btn": filter = new Gaussian3x3BlurFilter(); afterFilter = bitmapCanvas.ConvolutionFilter(filter); hBitmap = afterFilter.GetHbitmap(); MyImg.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); main_canvas.Children.Clear(); main_canvas.Children.Add(MyImg); break; case "Soften_Btn": filter = new SoftenFilter(); afterFilter = bitmapCanvas.ConvolutionFilter(filter); hBitmap = afterFilter.GetHbitmap(); MyImg.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); main_canvas.Children.Clear(); main_canvas.Children.Add(MyImg); break; case "HighPass_Btn": filter = new HighPass3x3Filter(); afterFilter = bitmapCanvas.ConvolutionFilter(filter); hBitmap = afterFilter.GetHbitmap(); MyImg.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); main_canvas.Children.Clear(); main_canvas.Children.Add(MyImg); break; case "Median_Btn": afterFilter = MedianFilter.CalculateMedianFilter(bitmapCanvas, 3, 0, false); hBitmap = afterFilter.GetHbitmap(); MyImg.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); main_canvas.Children.Clear(); main_canvas.Children.Add(MyImg); break; default: break; } }