Class GradientFillSettings
isi
[
bersembunyi
]GradientFillSettings class
Pengaturan efek isian gradien.
public class GradientFillSettings : BaseFillSettings, IGradientFillSettings
Konstruktor
Nama | Keterangan |
---|---|
GradientFillSettings() | Menginisialisasi instance baru dariGradientFillSettings kelas. |
Properti
Nama | Keterangan |
---|---|
AlignWithLayer { get; set; } | Mendapat atau menetapkan nilai yang menunjukkan apakah [sejajar dengan lapisan]. |
Angle { get; set; } | Mendapatkan atau mengatur sudut. |
Color { get; set; } | Mendapat atau mengatur warna. |
ColorPoints { get; set; } | Mendapat atau mengatur titik warna. |
Dither { get; set; } | Mendapat atau menetapkan nilai yang menunjukkan apakah iniGradientFillSettings adalah gentar. |
override FillType { get; } | Jenis isian |
GradientName { get; set; } | Mendapat atau menetapkan nama gradien. |
GradientType { get; set; } | Mendapat atau menyetel jenis gradien. |
HorizontalOffset { get; set; } | Mendapat atau menetapkan offset horizontal dalam persentase. |
Reverse { get; set; } | Mendapat atau menetapkan nilai yang menunjukkan apakah iniGradientFillSettings terbalik. |
Scale { get; set; } | Mendapat atau menyetel skala. |
TransparencyPoints { get; set; } | Mendapat atau menetapkan poin transparansi. |
VerticalOffset { get; set; } | Mendapat atau menetapkan offset vertikal dalam persentase. |
Metode
Nama | Keterangan |
---|---|
AddColorPoint() | Menambahkan titik warna. |
AddTransparencyPoint() | Menambahkan titik warna. |
RemoveColorPoint(IGradientColorPoint) | Menghilangkan titik warna. |
RemoveTransparencyPoint(IGradientTransparencyPoint) | Menghapus titik transparansi. |
static GenerateLfx2ResourceNodes() | Menghasilkan node sumber daya LFX2. |
Contoh
Kode berikut menunjukkan dukungan dari layer efek stroke dengan tipe isian - 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(Color.Black, fillSettings.Color);
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);
// Poin Warna
var colorPoints = fillSettings.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);
// Poin transparansi
var transparencyPoints = fillSettings.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);
// Tes pengeditan
fillSettings.Color = Color.Green;
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;
// Tambahkan titik warna baru
var colorPoint = fillSettings.AddColorPoint();
colorPoint.Color = Color.Green;
colorPoint.Location = 4096;
colorPoint.MedianPointLocation = 75;
// Ubah lokasi titik sebelumnya
fillSettings.ColorPoints[1].Location = 1899;
// Tambahkan titik transparansi baru
var transparencyPoint = fillSettings.AddTransparencyPoint();
transparencyPoint.Opacity = 25;
transparencyPoint.MedianPointLocation = 25;
transparencyPoint.Location = 4096;
// Ubah lokasi titik transparansi sebelumnya
fillSettings.TransparencyPoints[1].Location = 2411;
im.Save(exportPath);
}
// Uji file setelah diedit
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;
AssertAreEqual(Color.Green, fillSettings.Color);
AssertAreEqual(FillType.Gradient, fillSettings.FillType);
// Periksa titik warna
AssertAreEqual(3, fillSettings.ColorPoints.Length);
var point = fillSettings.ColorPoints[0];
AssertAreEqual(50, point.MedianPointLocation);
AssertAreEqual(Color.Black, point.Color);
AssertAreEqual(0, point.Location);
point = fillSettings.ColorPoints[1];
AssertAreEqual(50, point.MedianPointLocation);
AssertAreEqual(Color.White, point.Color);
AssertAreEqual(1899, point.Location);
point = fillSettings.ColorPoints[2];
AssertAreEqual(75, point.MedianPointLocation);
AssertAreEqual(Color.Green, point.Color);
AssertAreEqual(4096, point.Location);
// Periksa poin transparan
AssertAreEqual(3, fillSettings.TransparencyPoints.Length);
var transparencyPoint = fillSettings.TransparencyPoints[0];
AssertAreEqual(50, transparencyPoint.MedianPointLocation);
AssertAreEqual(100.00, transparencyPoint.Opacity);
AssertAreEqual(0, transparencyPoint.Location);
transparencyPoint = fillSettings.TransparencyPoints[1];
AssertAreEqual(50, transparencyPoint.MedianPointLocation);
AssertAreEqual(100.00, transparencyPoint.Opacity);
AssertAreEqual(2411, transparencyPoint.Location);
transparencyPoint = fillSettings.TransparencyPoints[2];
AssertAreEqual(25, transparencyPoint.MedianPointLocation);
AssertAreEqual(25.00, transparencyPoint.Opacity);
AssertAreEqual(4096, transparencyPoint.Location);
}
Lihat juga
- class BaseFillSettings
- interface IGradientFillSettings
- ruang nama Aspose.PSD.FileFormats.Psd.Layers.FillSettings
- perakitan Aspose.PSD