Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active April 25, 2022 22:36
Show Gist options
  • Save aspose-com-gists/10185f09105af11426103c583715068c to your computer and use it in GitHub Desktop.
Save aspose-com-gists/10185f09105af11426103c583715068c to your computer and use it in GitHub Desktop.
Apply Gaussian Blur Filter to an Image in C# .NET
string sourceFile = "layers.psd";
string outputPsd = "out_test.psd";
string outputPng = "out_test.png";
using (var image = (PsdImage)Image.Load(sourceFile))
{
SmartObjectLayer smartLayer = (SmartObjectLayer)image.Layers[1];
Layer maskLayer = image.Layers[2];
Layer regularLayer = image.Layers[3];
// Apply Gaussian blur filter
GaussianBlurSmartFilter gaussianBlur = new GaussianBlurSmartFilter();
gaussianBlur.Radius = 10;
gaussianBlur.Opacity = 50;
// Apply filter to SmartObject
gaussianBlur.Apply(smartLayer);
smartLayer.SmartFilters.UpdateResourceValues();
smartLayer.UpdateModifiedContent();
// Apply filter to layer mask
gaussianBlur.ApplyToMask(maskLayer);
// Apply filter to layer
gaussianBlur.Apply(regularLayer);
// Save output as PSD and PNG Image
image.Save(outputPsd);
image.Save(outputPng, new ImageOptions.PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment