Image Filters Using C# .NET

Filtering is one of the most common tasks performed on an image. All methods require at least one argument, ImageID, to identify the image where the filter is applied. For some methods, it’s also necessary to set the KernelSize parameter, which specifies the pixel size of the area where the filtering operation is performed.

To apply any filter method to a specific part of an image, use the SetROI method. If you don’t use the setROI method, the entire image will be filtered.

Some methods require additional parameters that are specific to the applied filtering operation.

List of All Available Filtering Methods

Specifying the Affected Area

To apply a filter to part of an image, specify the area where you want to perform the filtering operation using the SetROI method. This method takes the following parameters:

  • The coordinates of the top-left corner of the affected area.

  • The width of the affected area.

  • The height of the affected area.

After applying the filter, remember to reset the affected area with the ResetROI method.

Information

The origin of the coordinate system is the top left-corner of the original image.

To blur an area of 500×500 pixels with the top and left margins set to 100 pixels, use the following code:

using GdPictureImaging gdpictureImaging = new GdPictureImaging();
int imageID = gdpictureImaging.CreateGdPictureImageFromFile(@"C:\temp\source.jpg");
// Set the affected area.
gdpictureImaging.SetROI(100, 100, 500, 500);
// Blur the affected area.
gdpictureImaging.FxBlur(imageID);
// Reset the affected area.
gdpictureImaging.ResetROI();
gdpictureImaging.SaveAsPNG(imageID, @"C:\temp\output.png");
gdpictureImaging.ReleaseGdPictureImage(imageID);
Using gdpictureImaging As GdPictureImaging = New GdPictureImaging()
    Dim imageID As Integer = gdpictureImaging.CreateGdPictureImageFromFile("C:\temp\source.jpg")
    ' Set the affected area.
    gdpictureImaging.SetROI(100, 100, 500, 500)
    ' Blur the affected area.
    gdpictureImaging.FxBlur(imageID)
    ' Reset the affected area.
    gdpictureImaging.ResetROI()
    gdImage.SaveAsPNG(imageID, "C:\temp\output.png")
    gdpictureImaging.ReleaseGdPictureImage(imageID)
End Using
Used Methods

Related Topics

Parameters Specific to Filters

Some filtering methods require additional parameters to specify how the filtering operation is performed. One of those methods is the FxEmboss method. In addition to the required ImageID parameter, this method also accepts the BackColor parameter, which specifies the dominant color of the output image. The following code embosses the image and sets the dominant color to bisque:

using GdPictureImaging gdpictureImaging = new GdPictureImaging();
int imageID = gdpictureImaging.CreateGdPictureImageFromFile(@"C:\temp\source.jpg");
// Emboss the image and set the color to bisque.
gdpictureImaging.FxEmboss(imageID, Color.Bisque);
gdpictureImaging.SaveAsPNG(imageID, @"C:\temp\output.png");
gdpictureImaging.ReleaseGdPictureImage(imageID);
Dim gdpictureImaging As New GdPictureImaging()
Dim imageID As Integer = gdpictureImaging.CreateGdPictureImageFromFile("C:\temp\source.jpg")
' Emboss the image and set the color to bisque.
gdpictureImaging.FxEmboss(imageID, Color.Bisque)
gdpictureImaging.SaveAsPNG(imageID, "C:\temp\output.png")
gdpictureImaging.ReleaseGdPictureImage(imageID)
Used Methods

Related Topics