Blur images in C# .NET

Use one of the following methods to add the blur effect to images:

For each of these methods, you can apply the blur effect to a part of an image.

Standard blur

For blurring an entire image, use the FxBlur method. It only requires the image ID as its parameter.

To blur part of an image, refer to the Specifying the Affected Area section.

To blur an entire image, use the following code:

using GdPictureImaging gdpictureImaging = new GdPictureImaging();
int imageID = gdpictureImaging.CreateGdPictureImageFromFile(@"C:\temp\source.jpg");
// Blur the entire image.
gdpictureImaging.FxBlur(imageID);
gdpictureImaging.SaveAsPNG(imageID, @"C:\temp\output.png");
gdpictureImaging.ReleaseGdPictureImage(imageID);

Gaussian blur

To blur an entire image with a specific blur effect intensity, use the FxGaussian method. To define the blur intensity, use the KernelSize parameter. The higher the number, the more blurred an image becomes.

To blur part of an image, refer to the Specifying the Affected Area section.

To blur an entire image with the blur intensity set to 15, use the following code:

using GdPictureImaging gdpictureImaging = new GdPictureImaging();
int imageID = gdpictureImaging.CreateGdPictureImageFromFile(@"C:\temp\source.jpg");
int kernel = 15;
// Blur the entire image with the kernel size set to 15.
gdpictureImaging.FxGaussian(imageID, kernel);
gdpictureImaging.SaveAsPNG(imageID, @"C:\temp\output.png");
gdpictureImaging.ReleaseGdPictureImage(imageID);

Specifying the affected area

When using the FxBlur and FxGaussian methods, you can specify the area you want to blur. Use the SetROI method, which 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 blur effect, remember to reset the selected area with the ResetROI method.

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

To blur an image 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);