Class PatternFillSettings
Inhalt
[
Ausblenden
]PatternFillSettings class
Musterfülleffekteinstellungen
public class PatternFillSettings : BaseFillSettings, IPatternFillSettings
Eigenschaften
Name | Beschreibung |
---|---|
AlignWithLayer { get; set; } | Ruft einen Wert ab oder legt einen Wert fest, der angibt, ob [link with layer]. |
Color { get; set; } | Ruft die Farbe ab oder legt sie fest. |
override FillType { get; } | Der Füllungstyp |
HorizontalOffset { get; set; } | Ruft den horizontalen Versatz ab oder legt ihn fest. |
Linked { get; set; } | Ruft einen Wert ab oder legt einen Wert fest, der angibt, ob dies der Fall istPatternFillSettings ist verlinkt. |
PatternData { get; set; } | Ruft die Musterdaten ab oder legt sie fest. |
PatternHeight { get; set; } | Ruft die Höhe des Musters ab oder legt sie fest. |
PatternId { get; set; } | Ruft die Musterkennung ab oder legt sie fest. |
PatternName { get; set; } | Ruft den Namen des Musters ab oder legt ihn fest. |
PatternWidth { get; set; } | Ruft die Breite des Musters ab oder legt sie fest. |
PointType { get; set; } | Ruft den Punkttyp ab oder legt ihn fest. |
Scale { get; set; } | Ruft die Skalierung ab oder legt sie fest. |
VerticalOffset { get; set; } | Ruft den vertikalen Offset ab oder legt ihn fest. |
Methoden
Name | Beschreibung |
---|---|
static GenerateLfx2ResourceNodes(string, Color, string, string, double, bool, PointF) | Erzeugt die LFX2-Ressourcenknoten. |
Beispiele
Der folgende Code demonstriert die Unterstützung der Bearbeitung von Füllebenenmustern.
[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");
}
// Bearbeiten
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);
}
Der folgende Code demonstriert die Unterstützung der Stricheffektebene mit dem Fülltyp Muster.
[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
};
// Neue Daten vorbereiten
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);
}
// Datei nach Bearbeitung testen
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");
}
// Überprüfen Sie die Musterdaten
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);
}
Siehe auch
- class BaseFillSettings
- interface IPatternFillSettings
- namensraum Aspose.PSD.FileFormats.Psd.Layers.FillSettings
- Montage Aspose.PSD