# Apply Effects

Work with DsImaging to add advanced effects on images such as dithering, thresholding, gray scaling, and various RGB effects.

## Content

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](/document-solutions/dot-net-imaging-api/api/online/DS.Documents.Imaging/GrapeCity.Documents.Imaging.GcBitmap.ApplyEffect.html) 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](https://cdn.mescius.io/document-site-files/images/a5680f0e-2d32-45dc-8048-d3ef11d0dae7/images/grayscale.jpg?width=400) | ![Image of the house after applying brightness and contrast effect](https://cdn.mescius.io/document-site-files/images/a5680f0e-2d32-45dc-8048-d3ef11d0dae7/images/rgbbrightnesscontrast.jpg?width=400) |
| **TemperatureAndTintEffect** | **Gaussian Blur** |
| ![Image of the house after applying temperature and tint effect](https://cdn.mescius.io/document-site-files/images/a5680f0e-2d32-45dc-8048-d3ef11d0dae7/images/rgbtemptint.jpg?width=400) | ![Image of the house after applying gaussian blur effect](https://cdn.mescius.io/document-site-files/images/a5680f0e-2d32-45dc-8048-d3ef11d0dae7/images/gaussian-blur-effect.jpg?width=400) |
| **Thresholding** | **Dithering** |
| ![Image of the house after applying Thresholding effect](https://cdn.mescius.io/document-site-files/images/a5680f0e-2d32-45dc-8048-d3ef11d0dae7/images/thresholding.jpg?width=400) | ![Image of the house after applying Dithering effect](https://cdn.mescius.io/document-site-files/images/a5680f0e-2d32-45dc-8048-d3ef11d0dae7/images/dithering.jpg?width=400) |

| **Effects** | **Classes** | **Descriptions** |
| ------- | ------- | ------------ |
| Dithering | DitheringEffect | Allows you to apply dithering effect through 9 different algorithms which are provided by the DitheringMethod enumeration. <ul><li>Atkinson</li><li>Burks</li><li>FloydSteinberg </li><li>JarvisJudiceNinke</li><li>Sierra</li><li>SierraLite</li><li>Stucki</li><li>TwoRowSierra</li><li>NoDithering</li></ul> |
| 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. <ul><li>BT709 </li><li>BT601 </li><li>BT2100</li></ul> |
| 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<br>HueRotationEffect<br>SaturationEffect <br>SepiaEffect <br>TemperatureAndTintEffect <br>LuminanceToAlphaEffect <br>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](/document-solutions/dot-net-imaging-api/api/online/DS.Documents.Imaging/GrapeCity.Documents.Imaging.DitheringEffect.Get.html) method of the [DitheringEffect](/document-solutions/dot-net-imaging-api/api/online/DS.Documents.Imaging/GrapeCity.Documents.Imaging.DitheringEffect.html) 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.

    ```csharp
    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](/document-solutions/dot-net-imaging-api/api/online/DS.Documents.Imaging/GrapeCity.Documents.Imaging.GcBitmap.IsBlackAndWhite.html) and [IsGrayscale](/document-solutions/dot-net-imaging-api/api/online/DS.Documents.Imaging/GrapeCity.Documents.Imaging.GcBitmap.IsGrayscale.html) methods in the [GcBitmap](/document-solutions/dot-net-imaging-api/api/online/DS.Documents.Imaging/GrapeCity.Documents.Imaging.GcBitmap.html) 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:

```csharp
// 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](https://developer.mescius.com/documents-api-imaging/demos/basics/effects/dithering1/code-cs).