[]
        
(Showing Draft Content)

Apply Effects

Advanced imaging effects are helpful in a lot of scenarios such as low-color depth environment, image transmission, medical imaging, remote-sensing, acoustic imagery and forensic surveillance imagery.

DsImaging library offers great flexibility while working with these advanced effects which includes dithering, thresholding, gray scaling, Gaussian blur, and various RGB effects. DsImaging provides the ApplyEffect method in the GcBitmap class which takes the instance of class representing the effect as a parameter. These effects and the corresponding classes are described in detail in the table below. Please note that the ApplyEffect method applies a graphic effect to an image or a portion in-place, which means it stores the result back in the existing Bitmap object instead of storing it in a new instance.

Grayscale

BrightnessContrastEffect

Image of the house after applying grayscale effect

Image of the house after applying brightness and contrast effect

TemperatureAndTintEffect

Gaussian Blur

Image of the house after applying temperature and tint effect

Image of the house after applying gaussian blur effect

Thresholding

Dithering

Image of the house after applying Thresholding effect

Image of the house after applying Dithering effect

Effects

Classes

Descriptions

Dithering

DitheringEffect

Allows you to apply dithering effect through 9 different algorithms which are provided by the DitheringMethod enumeration.

  • Atkinson

  • Burks

  • FloydSteinberg

  • JarvisJudiceNinke

  • Sierra

  • SierraLite

  • Stucki

  • TwoRowSierra

  • NoDithering

Thresholding

BradleyThresholdingEffect OtsuThresholdingEffect

Allows you to apply two types of thresholding effects, Bradley's thresholding and Otsu's thresholding, through BradleyThresholdingEffect and OtsuThresholdingEffect class respectively.

Grayscaling

GrayscaleEffect

Allows you to apply grayscale effect as per the three grayscale standards provided by the GrayscaleStandard enumeration.

  • BT709

  • BT601

  • BT2100

Gaussian Blur

GaussianBlurEffect

Allows you to create a blur effect based on the Gaussian function over the entire input image or a part of the image using the Get method of GaussianBlurEffect class.

RGB effects

OpacityEffect

HueRotationEffect

SaturationEffect

SepiaEffect

TemperatureAndTintEffect

LuminanceToAlphaEffect

BrightnessContrastEffect GammaCorrectionEffect

Allows you to apply various RGB effects using their corresponding classes mentioned in the column on left hand side.

To apply a graphic effect, say dithering, on an image:

  1. Initialize the GcBitmap class.

  2. Invoke Get method of the DitheringEffect class to define the dithering effect that specifies the method to be used for dithering.

  3. Apply dithering effect to an image using the ApplyEffect method which accepts the defined dithering effect as its parameter.

    var imagePath = Path.Combine("Resources", "Images",
                    "color-vegetables-small.jpg");
    
    //Initialize GcBitmap           
    GcBitmap origBmp = new GcBitmap(imagePath,
                       new Rectangle(50, 50, 1024, 1024));
    
    //Apply Dithering effect FloydSteinberg
    origBmp.ApplyEffect(DitheringEffect.Get(DitheringMethod.FloydSteinberg),
                        new Rectangle(0, 0, 1024, 1024));
    
    //Save Dithering effect image
    origBmp.SaveAsJpeg("Dithering.jpg");

Similarly, you can apply any other effect on images as mentioned in the table above.

DsImaging library also provides IsBlackAndWhite and IsGrayscale methods in the GcBitmap class to check whether the image is already black and white or grayscale. Both methods work very quickly, as GcBitmap makes it easy to convert a colorful image to a grayscale or bi-level black and white image. These methods also skip unnecessary conversions if the original image is already grayscale or black and white. However, if the image is colorful, these methods just check a few pixels and return the result immediately.

The IsBlackAndWhite method checks whether all the pixels of the image are either opaque black (0xFF000000) or opaque white (0xFFFFFFFF). Transparent and semi-transparent pixels are neither black nor white.

The IsGrayscale method checks whether all pixels of the image are shades of gray, i.e., their alpha channel is set to 0xFF (fully opaque) and their red, green, and blue channels have the same value.

Refer to the following example code in order to check whether the image is already black and white or grayscale:

// Initialize GcBitmap and load the image.
using var bmp = new GcBitmap("qrcode.png");

// Check if black and white is applied.
if (bmp.IsBlackAndWhite())
{
    Console.WriteLine("The image is black and white.");
}

// Check if grayscale is applied.
if (bmp.IsGrayscale())
{
    Console.WriteLine("The image is grayscale.");
}

For more information about implementation of different effects using DsImaging, see DsImaging sample browser.