Class StrokeEffect
محتويات
[
يخفي
]StrokeEffect class
تأثير الحد Adobe® Photoshop® لطبقة PSD .
public class StrokeEffect : ILayerEffect
الخصائص
اسم | وصف |
---|---|
BlendMode { get; set; } | الحصول على أو تحديد وضع المزج . |
EffectType { get; } | يحصل على نوع من التأثير |
FillSettings { get; set; } | الحصول على أو تعيين إعدادات التعبئة. |
IsVisible { get; set; } | الحصول على أو تعيين قيمة تشير إلى ما إذا كان هذا المثيل مرئيًا. |
Opacity { get; set; } | الحصول على التعتيم أو تعيينه . |
Overprint { get; set; } | الحصول على أو تعيين قيمة تشير إلى ما إذا كان هذاStrokeEffect سوف يمزج السكتة الدماغية مع محتويات الطبقة الحالية. |
Position { get; set; } | الحصول على أو تعيين موضع تأثير الحد للتحكم في محاذاة ضربة الفرشاة لمحتوى طبقة PSD . يمكن أن تكون القيمةInside لرسم حدود داخل محتوى طبقة PSD ، أوOutside لرسم حدود حول محتوى طبقة PSD ، وCenter لرسم السكتة الدماغية من الداخل والخارج. |
Size { get; set; } | الحصول على أو تحديد عرض تأثير ضربة الفرشاة . |
أمثلة
يوضح مثال الكود التالي تجسيد تأثير Stroke مع Color Fill.
[C#]
// تنفيذ عرض تأثير Stroke باستخدام Color Fill للتصدير
string sourceFileName = "StrokeComplex.psd";
string exportPath = "StrokeComplexRendering.psd";
string exportPathPng = "StrokeComplexRendering.png";
var loadOptions = new PsdLoadOptions()
{
LoadEffectsResource = true
};
using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions))
{
for (int i = 0; i < im.Layers.Length; i++)
{
var effect = (StrokeEffect)im.Layers[i].BlendingOptions.Effects[0];
var settings = (ColorFillSettings)effect.FillSettings;
settings.Color = Color.DeepPink;
}
// حفظ مديرية الأمن العام
im.Save(exportPath, new PsdOptions());
// حفظ png
im.Save(exportPathPng, new PngOptions()
{
ColorType = PngColorType.TruecolorWithAlpha
});
}
يوضح الكود التالي دعم طبقة تأثير الحد بنوع التعبئة - اللون.
[C#]
void AssertAreEqual(object expected, object actual, string message = null)
{
if (!object.Equals(expected, actual))
{
throw new FormatException(message ?? "Objects are not equal.");
}
}
var sourceFileName = "Stroke.psd";
var exportPath = "StrokeColorChanged.psd";
var loadOptions = new PsdLoadOptions()
{
LoadEffectsResource = true
};
using (var im = (PsdImage)Image.Load(sourceFileName, loadOptions))
{
var colorStroke = (StrokeEffect)im.Layers[1].BlendingOptions.Effects[0];
AssertAreEqual(BlendMode.Normal, colorStroke.BlendMode);
AssertAreEqual((byte)255, colorStroke.Opacity);
AssertAreEqual(true, colorStroke.IsVisible);
var fillSettings = (ColorFillSettings)colorStroke.FillSettings;
AssertAreEqual(Color.Black, fillSettings.Color);
AssertAreEqual(FillType.Color, fillSettings.FillType);
fillSettings.Color = Color.Yellow;
colorStroke.Opacity = 127;
colorStroke.BlendMode = BlendMode.Color;
im.Save(exportPath);
}
// اختبار الملف بعد التحرير
using (var im = (PsdImage)Image.Load(exportPath, loadOptions))
{
var colorStroke = (StrokeEffect)im.Layers[1].BlendingOptions.Effects[0];
AssertAreEqual(BlendMode.Color, colorStroke.BlendMode);
AssertAreEqual((byte)127, colorStroke.Opacity);
AssertAreEqual(true, colorStroke.IsVisible);
var fillSettings = (ColorFillSettings)colorStroke.FillSettings;
AssertAreEqual(Color.Yellow, fillSettings.Color);
AssertAreEqual(FillType.Color, fillSettings.FillType);
}
يوضح الكود التالي دعم طبقة تأثير الحد بنوع التعبئة - نقش.
[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);
}
يوضح الكود التالي دعم طبقة تأثير الحد بنوع التعبئة - التدرج.
[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);
// نقاط اللون
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);
// نقاط الشفافية
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);
// اختبار التحرير
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;
// أضف نقطة لون جديدة
var colorPoint = fillSettings.AddColorPoint();
colorPoint.Color = Color.Green;
colorPoint.Location = 4096;
colorPoint.MedianPointLocation = 75;
// تغيير موقع النقطة السابقة
fillSettings.ColorPoints[1].Location = 1899;
// أضف نقطة شفافية جديدة
var transparencyPoint = fillSettings.AddTransparencyPoint();
transparencyPoint.Opacity = 25;
transparencyPoint.MedianPointLocation = 25;
transparencyPoint.Location = 4096;
// تغيير موقع نقطة الشفافية السابقة
fillSettings.TransparencyPoints[1].Location = 2411;
im.Save(exportPath);
}
// اختبار الملف بعد التحرير
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);
// تحقق من نقاط اللون
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);
// تحقق من النقاط الشفافة
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);
}
أنظر أيضا
- interface ILayerEffect
- مساحة الاسم Aspose.PSD.FileFormats.Psd.Layers.LayerEffects
- المجسم Aspose.PSD