Last active
April 7, 2022 09:38
-
-
Save aspose-com-gists/76cae61ffe66e2a8d50556081c44d9a5 to your computer and use it in GitHub Desktop.
Work with Smart Filters and Smart Objects in PSD File with C# .NET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sourceFilter = "r2_SmartFilters.psd"; | |
var outputPsd = "output.psd"; | |
using (var image = (PsdImage)Image.Load(sourceFilter)) | |
{ | |
SmartObjectLayer smartObj = (SmartObjectLayer)image.Layers[1]; | |
// edit smart filters | |
GaussianBlurSmartFilter gaussianBlur = (GaussianBlurSmartFilter)smartObj.SmartFilters.Filters[0]; | |
// check filter values | |
Console.WriteLine("Radius: " + gaussianBlur.Radius); // 3.1 | |
Console.WriteLine("Blend Mode: " + gaussianBlur.BlendMode); // BlendMode.Dissolve | |
Console.WriteLine("Opacity: " + gaussianBlur.Opacity); // 90d | |
Console.WriteLine("GuassianBlurEnabled: " + gaussianBlur.IsEnabled); // true | |
// update filter values | |
gaussianBlur.Radius = 1; | |
gaussianBlur.BlendMode = BlendMode.Divide; | |
gaussianBlur.Opacity = 75; | |
gaussianBlur.IsEnabled = false; | |
AddNoiseSmartFilter addNoise = (AddNoiseSmartFilter)smartObj.SmartFilters.Filters[1]; | |
addNoise.Distribution = NoiseDistribution.Uniform; | |
// add new filter items | |
var filters = new List<SmartFilter>(smartObj.SmartFilters.Filters); | |
filters.Add(new GaussianBlurSmartFilter()); | |
filters.Add(new AddNoiseSmartFilter()); | |
smartObj.SmartFilters.Filters = filters.ToArray(); | |
// apply changes | |
smartObj.SmartFilters.UpdateResourceValues(); | |
// Apply filters | |
smartObj.SmartFilters.Filters[0].Apply(image.Layers[2]); | |
smartObj.SmartFilters.Filters[4].ApplyToMask(image.Layers[2]); | |
image.Save(outputPsd); | |
} | |
using (var image = (PsdImage)Image.Load(outputPsd)) | |
{ | |
SmartObjectLayer smartObj = (SmartObjectLayer)image.Layers[1]; | |
GaussianBlurSmartFilter gaussianBlur = (Aspose.PSD.FileFormats.Psd.Layers.SmartFilters.GaussianBlurSmartFilter)smartObj.SmartFilters.Filters[0]; | |
// check filter values | |
Console.WriteLine("\n\n"); | |
Console.WriteLine("Radius: " + gaussianBlur.Radius); // 1d | |
Console.WriteLine("Blend Mode: " + gaussianBlur.BlendMode); // BlendMode.Divide | |
Console.WriteLine("Opacity: " + gaussianBlur.Opacity); // 75d | |
Console.WriteLine("GuassianBlurEnabled: " + gaussianBlur.IsEnabled); // false | |
Console.WriteLine(smartObj.SmartFilters.Filters[5] is GaussianBlurSmartFilter); // true | |
Console.WriteLine(smartObj.SmartFilters.Filters[6] is AddNoiseSmartFilter); // true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment