// Apply filter on the image private static void ApplyFilter(IFilter filter, ref Bitmap image) { if (filter is IFilterInformation) { IFilterInformation filterInfo = (IFilterInformation)filter; if (!filterInfo.FormatTransalations.ContainsKey(image.PixelFormat)) { if (filterInfo.FormatTransalations.ContainsKey(PixelFormat.Format24bppRgb)) { MessageBox.Show("The selected image processing routine may be applied to color image only.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show( "The selected image processing routine may be applied to grayscale or binary image only.\n\nUse grayscale (and threshold filter if required) before.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return; } } try { // apply filter to the image image = filter.Apply(image); } catch { MessageBox.Show("Error occured applying selected filter to the image", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static void AssertCanApply( this IFilterInformation filterInfo, PixelFormat format) { Debug.Assert( filterInfo.FormatTranslations.ContainsKey(format), string.Format("{0} cannot process an image " + "with the provided pixel format. Provided " + "format: {1}. Accepted formats: {2}.", filterInfo.GetType().Name, format.ToString(), string.Join(", ", filterInfo.FormatTranslations.Keys))); }
private static Bitmap ApplyFilter(IFilter filter, Bitmap image) { IFilterInformation filterInformation = filter as IFilterInformation; if (filterInformation != null && !filterInformation.FormatTranslations.ContainsKey(image.PixelFormat)) { if (filterInformation.FormatTranslations.ContainsKey(PixelFormat.Format24bppRgb)) { return(null); } return(null); } return(filter.Apply(image)); }