Class GrdmResource

GrdmResource class

Class GrdmResource. Contains information about Gradient-Map layer.

public class GrdmResource : AdjustmentLayerResource

Constructors

NameDescription
GrdmResource()The default constructor.

Properties

NameDescription
ColorModel { get; set; }Color Model. When ‘Gradient type’ = ‘Noise’, we can assign ‘Color Model’ to RGB/SHB/LAB (3/4/6).
ColorPoints { get; set; }Gets or sets the color points.
Dither { get; set; }Is gradient dithered.
ExpansionCount { get; set; }Expansion count ( = 2 for Photoshop 6.0).
GradientMode { get; set; }Mode for this gradient Determines ‘Gradient Type’ = ‘Solid/Noise’ (0/1).
GradientName { get; set; }Name of the gradient: Unicode string, padded.
Interpolation { get; set; }Interpolation. Determines Smoothness, when ‘Gradient Type’ = ‘Solid’ (GradientMode = 0).
override Key { get; }Gets the layer resource key.
override Length { get; }Gets the layer resource length in bytes.
MaximumColor { get; set; }Maximum color of PixelDataFormat.Rgba64Bpp format. Color has ARGB channels, Each channel is 16bit.
MinimumColor { get; set; }Minimum color of PixelDataFormat.Rgba64Bpp format. Color has ARGB channels, Each channel is 16bit.
override PsdVersion { get; }Gets the minimal psd version required for layer resource. 0 indicates no restrictions.
Reverse { get; set; }Is gradient reversed.
RndNumberSeed { get; set; }The random number seed used to generate colors for Noise gradient.
Roughness { get; set; }Roughness factor When ‘Gradient type’ = ‘Noise’, we can assign ‘Roughness’ (0 - 2048).
ShowTransparency { get; set; }Flag for showing transparency When ‘Gradient type’ = ‘Noise’, we can assign ‘Add transparency’ to true.
override Signature { get; }Gets the signature.
TransparencyPoints { get; set; }Gets or sets the transparency points.
UseVectorColor { get; set; }Flag for using vector color.

Methods

NameDescription
override Save(StreamContainer, int)Saves resource data to the specified stream container.
SetPsdVersion(ushort)Sets the minimal psd version required for layer resource. 0 indicates no restrictions.
override ToString()Returns a String that represents this instance.

Fields

NameDescription
const TypeToolKeyThe type tool info key.

Examples

The following code demonstrates support of GrdmResource resource.

[C#]

string sourceFile = "gradient_map_default.psd";
string outputFile = "gradient_map_res.psd";

using (var image = (PsdImage)Image.Load(sourceFile, new PsdLoadOptions()))
{
    Layer layer = image.Layers[1];
    GrdmResource grdmResource = (GrdmResource)layer.Resources[0];
            
    // check current values
    AssertAreEqual(false, grdmResource.Reverse);
    AssertAreEqual((ulong)65535, grdmResource.ColorPoints[1].RawColor.Components[2].Value);
    AssertAreEqual((ulong)65535, grdmResource.ColorPoints[1].RawColor.Components[3].Value);
            
            
    grdmResource.Reverse = true;
    // Red color for second gradient color point
    grdmResource.ColorPoints[1].RawColor.Components[1].Value = ushort.MaxValue;
    grdmResource.ColorPoints[1].RawColor.Components[2].Value = 0;
    grdmResource.ColorPoints[1].RawColor.Components[3].Value = 0;

    image.Save(outputFile, new PsdOptions());
}

using (var image = (PsdImage)Image.Load(outputFile))
{
    Layer layer = image.Layers[1];
    GrdmResource grdmResource = (GrdmResource)layer.Resources[0];
    
    // check changed values
    AssertAreEqual(true, grdmResource.Reverse);
    AssertAreEqual((ulong)0, grdmResource.ColorPoints[1].RawColor.Components[2].Value);
    AssertAreEqual((ulong)0, grdmResource.ColorPoints[1].RawColor.Components[3].Value);
}

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

See Also