OverviewThe purpose of the article is to be able to build a class that allows any C# programmer to perform image processing functionality. In my previous similar articles Image Processing in done in Windows Applications. This time the purpose is to try by WPF. The reason we are doing it in C# is that it very flexible for me. We can see that the code becomes somewhat more complex when we start moving pixels or changing values based on calculations that take into account all the pixel values.
ApplicationThe application uses the WPF. I have handled the images with a separate class called CurrentImageHandler in which all the image related operations are done including Saving, Graphics related operations. The Functionality includes getting image information, zooming, color filtering, brightening, contrasting, grayscale filtering, invert filtering, resizing with full resolution, rotating and flipping, cropping and inserting text, any other image and some geometric shapes. The image related functionalities are handled in a separate class library called ImageFunctions.dll. You can download ImageFunctions.dll from my previous article. 1. Thumbnail View
ThumbnailViewWindow tvWnd = new ThumbnailViewWindow(currImgHandler);
tvWnd.Show();2. Color FilterColor filters are sometimes classified according to their type of spectral absorption: short-wavelength pass, long-wavelength pass or band-pass; diffuse or sharp-cutting; monochromatic or conversion. The short-wavelength pass transmits all wavelengths up to the specified one and then absorbs. The long-wavelength pass is the opposite. Every filter is a band-pass filter when considered generally. It is very simple - it just adds or subtracts a value to each color. The most useful thing to do with this filter is to set two colors to -255 in order to strip them and see one color component of an image. For example, for red filter, keep the red component as it is and just subtract 255 from the green component and blue component. currImgHandler.CurrentFilterHandler.SetColorFilter(ColorFilterTypes.Red);
currImgHandler.CurrentFilterHandler.SetColorFilter(ColorFilterTypes.Green);
currImgHandler.CurrentFilterHandler.SetColorFilter(ColorFilterTypes.Blue); 3. BrightnessBrightening images are sometimes needed, it's a personal choice. Sometimes printing needs a lighter image than viewing. It is done just by adjusting the color components as per the user requirement. The input ranges between -255 and 255. BrightnessWindow bWnd = new BrightnessWindow();
bWnd.BrightnessValue = 0;
if (bWnd.ShowDialog().Value)
{
currImgHandler.CurrentBrightnessHandler.SetBrightness(bWnd.BrightnessValue);
PaintImage();
}
Read more: Codeproject
QR: