AddNoiseSmartFilter

AddNoiseSmartFilter class

The AddNoise smart filter.

public sealed class AddNoiseSmartFilter : SmartFilter

Constructors

Name Description
AddNoiseSmartFilter() Initializes a new instance of the AddNoiseSmartFilter class.

Properties

Name Description
AmountNoise { get; set; } Gets or sets The noise value amount.
BlendMode { get; set; } Gets or sets the blending mode.
Distribution { get; set; } Gets or sets the distribution of noise filter.
override FilterId { get; } Gets the smart filter type identifier.
IsEnabled { get; set; } Gets or sets the is enabled status of the smart filter.
IsMonochromatic { get; set; } Gets or sets the value of monochromatic.
override Name { get; } Gets the smart filter name.
Opacity { get; set; } Gets or sets the opacity value of smart filter.
SourceDescriptor { get; } The source descriptor structure with smart filter data.

Methods

Name Description
Apply(RasterImage) Applies the current filter to input RasterImage image.
ApplyToMask(Layer) Applies the current filter to input Layer mask data.
Clone() Makes the memberwise clone of the current instance of the type.

Fields

Name Description
const FilterType The identifier of current smart filter.

Examples

This example demonstrates the support of the smart filters interface.

[C#]

string sourceFilte = "r2_SmartFilters.psd";
string outputPsd = "out_r2_SmartFilters.psd";

void AssertAreEqual(object expected, object actual)
{
    if (!object.Equals(expected, actual))
    {
        throw new Exception("Objects are not equal.");
    }
}

using (var image = (PsdImage)Image.Load(sourceFilte))
{
    SmartObjectLayer smartObj = (SmartObjectLayer)image.Layers[1];

    // edit smart filters
    GaussianBlurSmartFilter gaussianBlur = (GaussianBlurSmartFilter)smartObj.SmartFilters.Filters[0];

    // check filter values
    AssertAreEqual(3.1, gaussianBlur.Radius);
    AssertAreEqual(BlendMode.Dissolve, gaussianBlur.BlendMode);
    AssertAreEqual(90d, gaussianBlur.Opacity);
    AssertAreEqual(true, gaussianBlur.IsEnabled);

    // 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 = (GaussianBlurSmartFilter)smartObj.SmartFilters.Filters[0];

    // check filter values
    AssertAreEqual(1d, gaussianBlur.Radius);
    AssertAreEqual(BlendMode.Divide, gaussianBlur.BlendMode);
    AssertAreEqual(75d, gaussianBlur.Opacity);
    AssertAreEqual(false, gaussianBlur.IsEnabled);

    AssertAreEqual(true, smartObj.SmartFilters.Filters[5] is GaussianBlurSmartFilter);
    AssertAreEqual(true, smartObj.SmartFilters.Filters[6] is AddNoiseSmartFilter);
}

See Also