Class PatternFillSettings
isi
[
bersembunyi
]PatternFillSettings class
Pengaturan efek isian pola
public class PatternFillSettings : BaseFillSettings, IPatternFillSettings
Properti
Nama | Keterangan |
---|---|
AlignWithLayer { get; set; } | Mendapat atau menetapkan nilai yang menunjukkan apakah [tautan dengan lapisan]. |
Color { get; set; } | Mendapat atau mengatur warna. |
override FillType { get; } | Jenis isian |
HorizontalOffset { get; set; } | Mendapat atau menyetel offset horizontal. |
Linked { get; set; } | Mendapat atau menetapkan nilai yang menunjukkan apakah iniPatternFillSettings ditautkan. |
PatternData { get; set; } | Mendapat atau menyetel data pola. |
PatternHeight { get; set; } | Mendapat atau menyetel tinggi pola. |
PatternId { get; set; } | Mendapat atau menyetel pengidentifikasi pola. |
PatternName { get; set; } | Mendapat atau menetapkan nama pola. |
PatternWidth { get; set; } | Mendapat atau mengatur lebar pola. |
PointType { get; set; } | Mendapat atau mengatur jenis titik. |
Scale { get; set; } | Mendapat atau menyetel skala. |
VerticalOffset { get; set; } | Mendapat atau menyetel offset vertikal. |
Metode
Nama | Keterangan |
---|---|
static GenerateLfx2ResourceNodes(string, Color, string, string, double, bool, PointF) | Menghasilkan node sumber daya LFX2. |
Contoh
Kode berikut menunjukkan dukungan dari pengeditan Fill Layer Pattern.
[C#]
string sourceFileName = "PatternFillLayer.psd";
string exportPath = "PatternFillLayer_Edited.psd";
double tolerance = 0.0001;
var im = (PsdImage)Image.Load(sourceFileName);
using (im)
{
foreach (var layer in im.Layers)
{
if (layer is FillLayer)
{
FillLayer fillLayer = (FillLayer)layer;
PatternFillSettings fillSettings = (PatternFillSettings)fillLayer.FillSettings;
if (fillSettings.HorizontalOffset != -46 ||
fillSettings.VerticalOffset != -45 ||
fillSettings.PatternId != "a6818df2-7532-494e-9615-8fdd6b7f38e5".ToUpperInvariant() ||
fillSettings.PatternName != "$$$/Presets/Patterns/OpticalSquares=Optical Squares" ||
fillSettings.AlignWithLayer != true ||
fillSettings.Linked != true ||
fillSettings.PatternHeight != 64 ||
fillSettings.PatternWidth != 64 ||
fillSettings.PatternData.Length != 4096 ||
Math.Abs(fillSettings.Scale - 50) > tolerance)
{
throw new Exception("PSD Image was read wrong");
}
// Mengedit
fillSettings.Scale = 300;
fillSettings.HorizontalOffset = 2;
fillSettings.VerticalOffset = -20;
fillSettings.PatternData = new int[]
{
Color.Red.ToArgb(), Color.Blue.ToArgb(), Color.Blue.ToArgb(),
Color.Blue.ToArgb(), Color.Red.ToArgb(), Color.Blue.ToArgb(),
Color.Blue.ToArgb(), Color.Blue.ToArgb(), Color.Red.ToArgb()
};
fillSettings.PatternHeight = 3;
fillSettings.PatternWidth = 3;
fillSettings.AlignWithLayer = false;
fillSettings.Linked = false;
fillSettings.PatternId = Guid.NewGuid().ToString();
fillLayer.Update();
break;
}
}
im.Save(exportPath);
}
Kode berikut menunjukkan dukungan dari layer efek stroke dengan tipe isian - Pola.
[C#]
void AssertAreEqual(object expected, object actual, string message = null)
{
if (expected is Array && actual is Array)
{
Array array1 = (Array)expected;
Array array2 = (Array)actual;
AssertAreEqual(array1.Length, array2.Length);
for (int i = 0; i < array1.Length; i++)
{
AssertAreEqual(array1.GetValue(i), array2.GetValue(i));
}
return;
}
if (!object.Equals(expected, actual))
{
throw new FormatException(message ?? "Objects are not equal.");
}
}
string sourceFileName = "Stroke.psd";
string exportPath = "StrokePatternChanged.psd";
var loadOptions = new PsdLoadOptions()
{
LoadEffectsResource = true
};
// Menyiapkan data baru
var newPattern = new int[]
{
Color.Aqua.ToArgb(), Color.Red.ToArgb(), Color.Red.ToArgb(), Color.Aqua.ToArgb(),
Color.Aqua.ToArgb(), Color.White.ToArgb(), Color.White.ToArgb(), Color.Aqua.ToArgb(),
Color.Aqua.ToArgb(), Color.White.ToArgb(), Color.White.ToArgb(), Color.Aqua.ToArgb(),
Color.Aqua.ToArgb(), Color.Red.ToArgb(), Color.Red.ToArgb(), Color.Aqua.ToArgb(),
};
var newPatternBounds = new Rectangle(0, 0, 4, 4);
var guid = Guid.NewGuid();
using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions))
{
var patternStroke = (StrokeEffect)im.Layers[3].BlendingOptions.Effects[0];
AssertAreEqual(BlendMode.Normal, patternStroke.BlendMode);
AssertAreEqual((byte)255, patternStroke.Opacity);
AssertAreEqual(true, patternStroke.IsVisible);
var fillSettings = (PatternFillSettings)patternStroke.FillSettings;
AssertAreEqual(FillType.Pattern, fillSettings.FillType);
patternStroke.Opacity = 127;
patternStroke.BlendMode = BlendMode.Color;
PattResource resource;
foreach (var globalLayerResource in im.GlobalLayerResources)
{
if (globalLayerResource is PattResource)
{
resource = (PattResource)globalLayerResource;
resource.Patterns[0].PatternId = guid.ToString();
resource.Patterns[0].Name = "$$$/Presets/Patterns/HorizontalLine1=Horizontal Line 9\0";
resource.Patterns[0].SetPattern(newPattern, newPatternBounds);
}
}
((PatternFillSettings)patternStroke.FillSettings).PatternName = "$$$/Presets/Patterns/HorizontalLine1=Horizontal Line 9\0";
((PatternFillSettings)patternStroke.FillSettings).PatternId = guid.ToString() + "\0";
im.Save(exportPath);
}
// Uji file setelah diedit
using (var im = (PsdImage)Image.Load(exportPath, loadOptions))
{
var patternStroke = (StrokeEffect)im.Layers[3].BlendingOptions.Effects[0];
PattResource resource = null;
foreach (var globalLayerResource in im.GlobalLayerResources)
{
if (globalLayerResource is PattResource)
{
resource = (PattResource)globalLayerResource;
}
}
if (resource == null)
{
throw new Exception("PattResource not found");
}
// Periksa data pola
AssertAreEqual(newPattern, resource.Patterns[0].PatternData);
AssertAreEqual(newPatternBounds, new Rectangle(0, 0, resource.Patterns[0].Width, resource.Patterns[0].Height));
AssertAreEqual(guid.ToString().ToUpperInvariant(), resource.Patterns[0].PatternId);
AssertAreEqual(BlendMode.Color, patternStroke.BlendMode);
AssertAreEqual((byte)127, patternStroke.Opacity);
AssertAreEqual(true, patternStroke.IsVisible);
var fillSettings = (PatternFillSettings)patternStroke.FillSettings;
AssertAreEqual(FillType.Pattern, fillSettings.FillType);
}
Lihat juga
- class BaseFillSettings
- interface IPatternFillSettings
- ruang nama Aspose.PSD.FileFormats.Psd.Layers.FillSettings
- perakitan Aspose.PSD