Class GradientFillSettings
Contents
[
Hide
]GradientFillSettings class
Base gradient definition class. It contains common properties for both types of gradient (Solid and Noise).
public class GradientFillSettings : BaseFillSettings, IGradientFillSettings
Constructors
Name | Description |
---|---|
GradientFillSettings() | The default constructor. |
Properties
Name | Description |
---|---|
AlignWithLayer { get; set; } | Gets or sets a value indicating whether [align with layer]. |
Angle { get; set; } | Gets or sets the angle. |
Dither { get; set; } | Gets or sets a value indicating whether this GradientFillSettings is dither. |
override FillType { get; } | The fill type. |
Gradient { get; set; } | Gets or sets specific gradient definition instance (Solid/Noise). |
GradientType { get; set; } | Gets or sets the type of the gradient. |
HorizontalOffset { get; set; } | Gets or sets the horizontal offset in percentage. |
Reverse { get; set; } | Gets or sets a value indicating whether this GradientFillSettings is reverse. |
Scale { get; set; } | Gets or sets the scale. |
VerticalOffset { get; set; } | Gets or sets the vertical offset in percentage. |
Examples
The following code demonstrates support of the stroke effect layer with fill type - Gradient.
[C#]
void AssertIsTrue(bool condition, string message)
{
if (!condition)
{
throw new FormatException(message);
}
}
void AssertAreEqual(object expected, object actual, string message = null)
{
if (!object.Equals(expected, actual))
{
throw new FormatException(message ?? "Objects are not equal.");
}
}
string sourceFileName = "Stroke.psd";
string exportPath = "StrokeGradientChanged.psd";
var loadOptions = new PsdLoadOptions()
{
LoadEffectsResource = true
};
using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions))
{
var gradientStroke = (StrokeEffect)im.Layers[2].BlendingOptions.Effects[0];
AssertAreEqual(BlendMode.Normal, gradientStroke.BlendMode);
AssertAreEqual((byte)255, gradientStroke.Opacity);
AssertAreEqual(true, gradientStroke.IsVisible);
var fillSettings = (GradientFillSettings)gradientStroke.FillSettings;
AssertAreEqual(FillType.Gradient, fillSettings.FillType);
AssertAreEqual(true, fillSettings.AlignWithLayer);
AssertAreEqual(GradientType.Linear, fillSettings.GradientType);
AssertIsTrue(Math.Abs(90 - fillSettings.Angle) < 0.001, "Angle is incorrect");
AssertAreEqual(false, fillSettings.Dither);
AssertIsTrue(Math.Abs(0 - fillSettings.HorizontalOffset) < 0.001, "Horizontal offset is incorrect");
AssertIsTrue(Math.Abs(0 - fillSettings.VerticalOffset) < 0.001, "Vertical offset is incorrect");
AssertAreEqual(false, fillSettings.Reverse);
// Color Points
var solidGradient = (SolidGradient)fillSettings.Gradient;
var colorPoints = solidGradient.ColorPoints;
AssertAreEqual(2, colorPoints.Length);
AssertAreEqual(Color.Black, colorPoints[0].Color);
AssertAreEqual(0, colorPoints[0].Location);
AssertAreEqual(50, colorPoints[0].MedianPointLocation);
AssertAreEqual(Color.White, colorPoints[1].Color);
AssertAreEqual(4096, colorPoints[1].Location);
AssertAreEqual(50, colorPoints[1].MedianPointLocation);
// Transparency points
var transparencyPoints = solidGradient.TransparencyPoints;
AssertAreEqual(2, transparencyPoints.Length);
AssertAreEqual(0, transparencyPoints[0].Location);
AssertAreEqual(50, transparencyPoints[0].MedianPointLocation);
AssertAreEqual(100.00, transparencyPoints[0].Opacity);
AssertAreEqual(4096, transparencyPoints[1].Location);
AssertAreEqual(50, transparencyPoints[1].MedianPointLocation);
AssertAreEqual(100.00, transparencyPoints[1].Opacity);
// Test editing
gradientStroke.Opacity = 127;
gradientStroke.BlendMode = BlendMode.Color;
fillSettings.AlignWithLayer = false;
fillSettings.GradientType = GradientType.Radial;
fillSettings.Angle = 45;
fillSettings.Dither = true;
fillSettings.HorizontalOffset = 15;
fillSettings.VerticalOffset = 11;
fillSettings.Reverse = true;
// Add new color point
var colorPoint = solidGradient.AddColorPoint();
colorPoint.Color = Color.Green;
colorPoint.Location = 4096;
colorPoint.MedianPointLocation = 75;
// Change location of previous point
solidGradient.ColorPoints[1].Location = 1899;
// Add new transparency point
var transparencyPoint = solidGradient.AddTransparencyPoint();
transparencyPoint.Opacity = 25;
transparencyPoint.MedianPointLocation = 25;
transparencyPoint.Location = 4096;
// Change location of previous transparency point
solidGradient.TransparencyPoints[1].Location = 2411;
im.Save(exportPath);
}
// Test file after edit
using (var im = (PsdImage)Image.Load(exportPath, loadOptions))
{
var gradientStroke = (StrokeEffect)im.Layers[2].BlendingOptions.Effects[0];
AssertAreEqual(BlendMode.Color, gradientStroke.BlendMode);
AssertAreEqual((byte)127, gradientStroke.Opacity);
AssertAreEqual(true, gradientStroke.IsVisible);
var fillSettings = (GradientFillSettings)gradientStroke.FillSettings;
var solidGradient = (SolidGradient)fillSettings.Gradient;
AssertAreEqual(FillType.Gradient, fillSettings.FillType);
// Check color points
AssertAreEqual(3, solidGradient.ColorPoints.Length);
var point = solidGradient.ColorPoints[0];
AssertAreEqual(50, point.MedianPointLocation);
AssertAreEqual(Color.Black, point.Color);
AssertAreEqual(0, point.Location);
point = solidGradient.ColorPoints[1];
AssertAreEqual(50, point.MedianPointLocation);
AssertAreEqual(Color.White, point.Color);
AssertAreEqual(1899, point.Location);
point = solidGradient.ColorPoints[2];
AssertAreEqual(75, point.MedianPointLocation);
AssertAreEqual(Color.Green, point.Color);
AssertAreEqual(4096, point.Location);
// Check transparent points
AssertAreEqual(3, solidGradient.TransparencyPoints.Length);
var transparencyPoint = solidGradient.TransparencyPoints[0];
AssertAreEqual(50, transparencyPoint.MedianPointLocation);
AssertAreEqual(100.00, transparencyPoint.Opacity);
AssertAreEqual(0, transparencyPoint.Location);
transparencyPoint = solidGradient.TransparencyPoints[1];
AssertAreEqual(50, transparencyPoint.MedianPointLocation);
AssertAreEqual(100.00, transparencyPoint.Opacity);
AssertAreEqual(2411, transparencyPoint.Location);
transparencyPoint = solidGradient.TransparencyPoints[2];
AssertAreEqual(25, transparencyPoint.MedianPointLocation);
AssertAreEqual(25.00, transparencyPoint.Opacity);
AssertAreEqual(4096, transparencyPoint.Location);
}
See Also
- class BaseFillSettings
- interface IGradientFillSettings
- namespace Aspose.PSD.FileFormats.Psd.Layers.FillSettings
- assembly Aspose.PSD