Class PatternFillSettings
Contenido
[
Ocultar
]PatternFillSettings class
Configuración del efecto de relleno de patrón
public class PatternFillSettings : BaseFillSettings, IPatternFillSettings
Propiedades
Nombre | Descripción |
---|---|
AlignWithLayer { get; set; } | Obtiene o establece un valor que indica si [enlace con capa]. |
Color { get; set; } | Obtiene o establece el color. |
override FillType { get; } | El tipo de relleno |
HorizontalOffset { get; set; } | Obtiene o establece el desplazamiento horizontal. |
Linked { get; set; } | Obtiene o establece un valor que indica si estePatternFillSettings está vinculado. |
PatternData { get; set; } | Obtiene o establece los datos del patrón. |
PatternHeight { get; set; } | Obtiene o establece la altura del patrón. |
PatternId { get; set; } | Obtiene o establece el identificador del patrón. |
PatternName { get; set; } | Obtiene o establece el nombre del patrón. |
PatternWidth { get; set; } | Obtiene o establece el ancho del patrón. |
PointType { get; set; } | Obtiene o establece el tipo del punto. |
Scale { get; set; } | Obtiene o establece la escala. |
VerticalOffset { get; set; } | Obtiene o establece el desplazamiento vertical. |
Métodos
Nombre | Descripción |
---|---|
static GenerateLfx2ResourceNodes(string, Color, string, string, double, bool, PointF) | Genera los nodos de recursos LFX2. |
Ejemplos
El código siguiente demuestra la compatibilidad con la edición de patrón de capa de relleno.
[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");
}
// Edición
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);
}
El siguiente código demuestra la compatibilidad de la capa de efecto de trazo con el tipo de relleno: patrón.
[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
};
// Preparando nuevos datos
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);
}
// Archivo de prueba después de editar
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");
}
// Comprobar los datos del patrón
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);
}
Ver también
- class BaseFillSettings
- interface IPatternFillSettings
- espacio de nombres Aspose.PSD.FileFormats.Psd.Layers.FillSettings
- asamblea Aspose.PSD