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 a quick blur of an entire image, use the FxBlur method. It only requires the image ID as its parameter.

Information

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);
Using gdpictureImaging As GdPictureImaging = New GdPictureImaging()
    Dim imageID As Integer = gdpictureImaging.CreateGdPictureImageFromFile("C:\temp\source.jpg")
    ' Blur the entire image.
    gdpictureImaging.FxBlur(imageID)
    gdpictureImaging.SaveAsPNG(imageID, "C:\temp\output.png")
    gdpictureImaging.ReleaseGdPictureImage(imageID)
End Using
Used Methods

Related Topics

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.

Information

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);
Using gdpictureImaging As GdPictureImaging = New GdPictureImaging()
    Dim imageID As Integer = gdpictureImaging.CreateGdPictureImageFromFile("C:\temp\source.jpg")
    Dim kernel = 15
    ' Blur the entire image with kernel size set to 15.
    gdpictureImaging.FxGaussian(imageID, kernel)
    gdpictureImaging.SaveAsPNG(imageID, "C:\temp\output.png")
    gdpictureImaging.ReleaseGdPictureImage(imageID)
End Using
Used Methods

Related Topics

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.

Information

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);
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()
    gdpictureImaging.SaveAsPNG(imageID, "C:\temp\output.png")
    gdpictureImaging.ReleaseGdPictureImage(imageID)
End Using
Used Methods

Related Topics