Class PatternFillSettings
内容
[
隐藏
]PatternFillSettings class
图案填充效果设置
public class PatternFillSettings : BaseFillSettings, IPatternFillSettings
特性
姓名 | 描述 |
---|---|
AlignWithLayer { get; set; } | 获取或设置一个值,该值指示是否[与图层链接]. |
Color { get; set; } | 获取或设置颜色。 |
override FillType { get; } | 填充类型 |
HorizontalOffset { get; set; } | 获取或设置水平偏移量。 |
Linked { get; set; } | 获取或设置一个值,指示是否这PatternFillSettings 链接. |
PatternData { get; set; } | 获取或设置模式数据。 |
PatternHeight { get; set; } | 获取或设置图案的高度。 |
PatternId { get; set; } | 获取或设置模式标识符。 |
PatternName { get; set; } | 获取或设置模式的名称。 |
PatternWidth { get; set; } | 获取或设置图案的宽度。 |
PointType { get; set; } | 获取或设置点的类型。 |
Scale { get; set; } | 获取或设置比例。 |
VerticalOffset { get; set; } | 获取或设置垂直偏移量。 |
方法
姓名 | 描述 |
---|---|
static GenerateLfx2ResourceNodes(string, Color, string, string, double, bool, PointF) | 生成 LFX2 资源节点。 |
例子
以下代码演示了对 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");
}
// 编辑
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);
}
以下代码演示了对填充类型为 Pattern 的笔触效果图层的支持。
[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
};
// 准备新数据
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);
}
// 编辑后的测试文件
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");
}
// 检查模式数据
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);
}
也可以看看
- class BaseFillSettings
- interface IPatternFillSettings
- 命名空间 Aspose.PSD.FileFormats.Psd.Layers.FillSettings
- 部件 Aspose.PSD