/// <summary> /// Processes the image. /// </summary> /// <param name="factory"> /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class containing /// the image to process. /// </param> /// <returns> /// The processed image from the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class. /// </returns> public Image ProcessImage(ImageFactory factory) { Bitmap newImage = null; Image image = factory.Image; Tuple <IEdgeFilter, bool> parameters = this.DynamicParameter; IEdgeFilter filter = parameters.Item1; bool greyscale = parameters.Item2; try { ConvolutionFilter convolutionFilter = new ConvolutionFilter(filter, greyscale); // Check and assign the correct method. Don't use reflection for speed. newImage = filter is I2DEdgeFilter ? convolutionFilter.Process2DFilter((Bitmap)image) : convolutionFilter.ProcessFilter((Bitmap)image); image.Dispose(); image = newImage; } catch (Exception ex) { if (newImage != null) { newImage.Dispose(); } throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex); } return(image); }
/// <summary> /// Processes the image. /// </summary> /// <param name="factory"> /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class containing /// the image to process. /// </param> /// <returns> /// The processed image from the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class. /// </returns> public Image ProcessImage(ImageFactory factory) { var image = factory.Image; Tuple <IEdgeFilter, bool> parameters = DynamicParameter; var filter = parameters.Item1; var greyscale = parameters.Item2; try { var convolutionFilter = new ConvolutionFilter(filter, greyscale); // Check and assign the correct method. Don't use reflection for speed. return(filter is I2DEdgeFilter ? convolutionFilter.Process2DFilter((Bitmap)image) : convolutionFilter.ProcessFilter((Bitmap)image)); } catch (Exception ex) { throw new ImageProcessingException("Error processing image with " + GetType().Name, ex); } }