레이어 벡터 마스크
레이어 벡터 마스크 개요
벡터 마스크는 레이어의 내용을 자르는 해상도에 독립적인 경로입니다. 벡터 마스크는 일반적으로 픽셀 기반 도구로 생성된 것보다 정확합니다. 핀 또는 모양 도구를 사용하여 벡터 마스크를 생성합니다.
Aspose.PSD는 벡터 마스크의 렌더링 및 적용을 지원합니다. 벡터 마스크를 편집하는 방법은 벡터 경로를 편집함으로써 이루어집니다.
Aspose.PSD의 벡터 경로
Aspose.PSD에서 벡터 경로에 액세스하려면 VsmsResouce 및 VmskResouce 자원을 통해 제공되며, 이들은 VectorPathDataResource의 하위 클래스입니다.
벡터 경로 편집 방법
벡터 경로 구조
경로를 조작하기 위한 기본 구조는 VectorPathRecord입니다. 그러나 편리성을 위해 다음 솔루션이 제안됩니다.
벡터 경로의 쉬운 편집을 위해 VectorPath 클래스를 사용해야 하며, 이 클래스에는 VectorPathDataResource에서 파생된 자원의 벡터 데이터를 편리하게 편집하는 메서드가 포함되어 있습니다.
VectorPath 유형의 개체를 만들어 시작합니다.
편리를 위해, VectorDataProvider.CreateVectorPathForLayer 정적 메서드를 사용하면 입력 레이어에서 벡터 리소스를 찾아 그를 기반으로 한 VectorPath 개체를 만들 수 있습니다.
모든 편집을 마친 후, 변경된 VectorPath 개체를 VectorDataProvider.UpdateLayerFromVectorPath 정적 메서드를 사용하여 레이어에 적용할 수 있습니다.
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
string fileName = "PathExample.psd"; | |
using (var psdImage = (PsdImage)Image.Load(fileName)) | |
{ | |
// Choose a layer with vector data that you want to edit. | |
Layer layer = psdImage.Layers[1]; | |
// Now we can use VectorPath instance and manipulate path data. | |
VectorPath vectorPath = VectorDataProvider.CreateVectorPathForLayer(layer); | |
// Apply changes from 'vectorPath' field to the layer. | |
VectorDataProvider.UpdateLayerFromVectorPath(layer, vectorPath); | |
} |
VectorPath 유형에는 PathShape 요소 목록이 포함되어 있으며, 하나 이상의 모양으로 구성된 전체 벡터 이미지를 설명합니다.
각 PathShape은 별도의 베지어 점(점) 세트로 구성된 벡터 도형입니다.
점은 도형을 구성하는 포인트로서 BezierKnot 유형의 객체입니다.
다음 코드 예제에서 도형과 점에 액세스하는 방법을 보여줍니다.
// Accessing a figure and points. | |
PathShape pathShape = vectorPath.Shapes[0]; | |
BezierKnot firstKnot = pathShape.Points[0]; |
모양을 만드는 방법
모양을 편집하려면 VectorPath.Shapes 목록에서 기존 모양을 가져오거나 PathShape 인스턴스를 생성하고 해당 목록에 추가하여 새로운 모양을 추가해야 합니다.
// Adds new one shape | |
vectorPath.Shapes.Add(new PathShape()); | |
// or gets an existing | |
PathShape pathShape = vectorPath.Shapes[0]; |
점(포인트)을 추가하는 방법
PathShape.Points 속성을 사용하여 모양의 포인트를 일반 List의 요소로 조작할 수 있으며, 예를 들어 모양 포인트를 추가할 수 있습니다:
// Add new shape with points | |
PathShape newShape = new PathShape(); | |
newShape.Points.Add(new BezierKnot(new PointF(65, 175), true)); | |
newShape.Points.Add(new BezierKnot(new PointF(65, 210), true)); | |
newShape.Points.Add(new BezierKnot(new PointF(190, 210), true)); | |
newShape.Points.Add(new BezierKnot(new PointF(190, 175), true)); | |
vectorPath.Shapes.Add(newShape); |
베지어 점에는 앵커 포인트와 두 개의 제어 포인트가 포함됩니다.
앵커 포인트와 제어 포인트가 동일한 값인 경우 해당 노드는 예각을 가집니다.
Photoshop에서 발생하는 것과 유사하게 앵커 포인트 위치를 변경하려면 BezierKnot에 Shift 메서드가 있습니다.
다음 코드 예제는 전체 베지어 점을 Y 좌표를 통해 수직으로 이동하는 방법을 보여줍니다:
PathShape.Points 속성을 사용하여 모양의 포인트를 일반 List의 요소로 조작할 수 있으며, 예를 들어 모양 포인트를 추가할 수 있습니다:
pathShape.Points[0].Shift(0, 25); |
PathShape 속성
PathShape 편집은 노드 편집으로 제한되지 않으며, 이 유형에는 다른 속성도 있습니다.
경로 작업(부울 작업)
PathOperations 속성은 여러 모양이 어떻게 혼합되는지를 정의하는 부울 연산이라고 불립니다.
다음과 같은 가능한 값이 있습니다:
- 0 = 중첩된 모양 제외(XOR 연산).
- 1 = 모양 결합(OR 연산).
- 2 = 앞 모양 뺌(NOT 연산).
- 3 = 모양 영역 교차(AND 연산).
IsClosed 속성
또한 PathShape.IsClosed 속성을 사용하여 모양의 첫 번째와 마지막 점이 연결되었는지를 확인할 수 있습니다.
닫힌 모양 | 열린 모양 |
---|---|
![]() |
![]() |
FillColor 속성
어떤 도형도 고유한 색상을 가질 수 있으므로 VectorPath.FillColor 속성을 사용하여 전체 벡터 경로의 색상을 변경할 수 있습니다.
PathShape.Points 속성을 사용하여 모양의 포인트를 일반 List의 요소로 조작할 수 있으며, 예를 들어 모양 포인트를 추가할 수 있습니다:
vectorPath.FillColor = Color.Violet; |
여기에서 VectorDataProvider 및 관련 클래스의 소스 코드를 찾을 수 있습니다:
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
private static void CreatingVectorPathExample(string outputPsd = "outputPsd.psd") | |
{ | |
using (var psdImage = (PsdImage)Image.Create(new PsdOptions() { Source = new StreamSource(new MemoryStream()), }, 500, 500)) | |
{ | |
FillLayer layer = FillLayer.CreateInstance(FillType.Color); | |
psdImage.AddLayer(layer); | |
VectorPath vectorPath = VectorDataProvider.CreateVectorPathForLayer(layer); | |
vectorPath.FillColor = Color.IndianRed; | |
PathShape shape = new PathShape(); | |
shape.Points.Add(new BezierKnot(new PointF(50, 150), true)); | |
shape.Points.Add(new BezierKnot(new PointF(100, 200), true)); | |
shape.Points.Add(new BezierKnot(new PointF(0, 200), true)); | |
vectorPath.Shapes.Add(shape); | |
VectorDataProvider.UpdateLayerFromVectorPath(layer, vectorPath, true); | |
psdImage.Save(outputPsd); | |
} | |
} | |
#region Vector path editor (Here placed classes for edit vector paths). | |
/// <summary> | |
/// The class that provides work between <see cref="Layer"/> and <see cref="VectorPath"/>. | |
/// </summary> | |
public static class VectorDataProvider | |
{ | |
/// <summary> | |
/// Creates the <see cref="VectorPath"/> instance based on resources from input layer. | |
/// </summary> | |
/// <param name="psdLayer">The psd layer.</param> | |
/// <returns>the <see cref="VectorPath"/> instance based on resources from input layer.</returns> | |
public static VectorPath CreateVectorPathForLayer(Layer psdLayer) | |
{ | |
ValidateLayer(psdLayer); | |
Size imageSize = psdLayer.Container.Size; | |
VectorPathDataResource pathResource = FindVectorPathDataResource(psdLayer, true); | |
SoCoResource socoResource = FindSoCoResource(psdLayer, true); | |
VectorPath vectorPath = new VectorPath(pathResource, imageSize); | |
if (socoResource != null) | |
{ | |
vectorPath.FillColor = socoResource.Color; | |
} | |
return vectorPath; | |
} | |
/// <summary> | |
/// Updates the input layer resources from <see cref="VectorPath"/> instance, or replace by new path resource and updates. | |
/// </summary> | |
/// <param name="psdLayer">The psd layer.</param> | |
/// <param name="vectorPath">The vector path.</param> | |
/// <param name="imageSize">The image size to correct converting point coordinates.</param> | |
public static void UpdateLayerFromVectorPath(Layer psdLayer, VectorPath vectorPath, bool createIfNotExist = false) | |
{ | |
ValidateLayer(psdLayer); | |
VectorPathDataResource pathResource = FindVectorPathDataResource(psdLayer, createIfNotExist); | |
VogkResource vogkResource = FindVogkResource(psdLayer, createIfNotExist); | |
SoCoResource socoResource = FindSoCoResource(psdLayer, createIfNotExist); | |
Size imageSize = psdLayer.Container.Size; | |
UpdateResources(pathResource, vogkResource, socoResource, vectorPath, imageSize); | |
ReplaceVectorPathDataResourceInLayer(psdLayer, pathResource, vogkResource, socoResource); | |
} | |
/// <summary> | |
/// Removes the vector path data from input layer. | |
/// </summary> | |
/// <param name="psdLayer">The psd layer.</param> | |
public static void RemoveVectorPathDataFromLayer(Layer psdLayer) | |
{ | |
List<LayerResource> oldResources = new List<LayerResource>(psdLayer.Resources); | |
List<LayerResource> newResources = new List<LayerResource>(); | |
for (int i = 0; i < oldResources.Count; i++) | |
{ | |
LayerResource resource = oldResources[i]; | |
if (resource is VectorPathDataResource || resource is VogkResource || resource is SoCoResource) | |
{ | |
continue; | |
} | |
else | |
{ | |
newResources.Add(resource); | |
} | |
} | |
psdLayer.Resources = newResources.ToArray(); | |
} | |
/// <summary> | |
/// Updates resources data from <see cref="VectorPath"/> instance. | |
/// </summary> | |
/// <param name="pathResource">The path resource.</param> | |
/// <param name="vogkResource">The vector origination data resource.</param> | |
/// <param name="socoResource">The solid color resource.</param> | |
/// <param name="vectorPath">The vector path.</param> | |
/// <param name="imageSize">The image size to correct converting point coordinates.</param> | |
private static void UpdateResources(VectorPathDataResource pathResource, VogkResource vogkResource, SoCoResource socoResource, VectorPath vectorPath, Size imageSize) | |
{ | |
pathResource.Version = vectorPath.Version; | |
pathResource.IsNotLinked = vectorPath.IsNotLinked; | |
pathResource.IsDisabled = vectorPath.IsDisabled; | |
pathResource.IsInverted = vectorPath.IsInverted; | |
List<VectorShapeOriginSettings> originSettings = new List<VectorShapeOriginSettings>(); | |
List<VectorPathRecord> path = new List<VectorPathRecord>(); | |
path.Add(new PathFillRuleRecord(null)); | |
path.Add(new InitialFillRuleRecord(vectorPath.IsFillStartsWithAllPixels)); | |
for (ushort i = 0; i < vectorPath.Shapes.Count; i++) | |
{ | |
PathShape shape = vectorPath.Shapes[i]; | |
shape.ShapeIndex = i; | |
path.AddRange(shape.ToVectorPathRecords(imageSize)); | |
originSettings.Add(new VectorShapeOriginSettings() { IsShapeInvalidated = true, OriginIndex = i }); | |
} | |
pathResource.Paths = path.ToArray(); | |
vogkResource.ShapeOriginSettings = originSettings.ToArray(); | |
socoResource.Color = vectorPath.FillColor; | |
} | |
/// <summary> | |
/// Replaces resources in layer by updated or new ones. | |
/// </summary> | |
/// <param name="psdLayer">The psd layer.</param> | |
/// <param name="pathResource">The path resource.</param> | |
/// <param name="vogkResource">The vector origination data resource.</param> | |
/// <param name="socoResource">The solid color resource.</param> | |
private static void ReplaceVectorPathDataResourceInLayer(Layer psdLayer, VectorPathDataResource pathResource, VogkResource vogkResource, SoCoResource socoResource) | |
{ | |
bool pathResourceExist = false; | |
bool vogkResourceExist = false; | |
bool socoResourceExist = false; | |
List<LayerResource> resources = new List<LayerResource>(psdLayer.Resources); | |
for (int i = 0; i < resources.Count; i++) | |
{ | |
LayerResource resource = resources[i]; | |
if (resource is VectorPathDataResource) | |
{ | |
resources[i] = pathResource; | |
pathResourceExist = true; | |
} | |
else if (resource is VogkResource) | |
{ | |
resources[i] = vogkResource; | |
vogkResourceExist = true; | |
} | |
else if (resource is SoCoResource) | |
{ | |
resources[i] = socoResource; | |
socoResourceExist = true; | |
} | |
} | |
if (!pathResourceExist) | |
{ | |
resources.Add(pathResource); | |
} | |
if (!vogkResourceExist) | |
{ | |
resources.Add(vogkResource); | |
} | |
if (!socoResourceExist) | |
{ | |
resources.Add(socoResource); | |
} | |
psdLayer.Resources = resources.ToArray(); | |
} | |
/// <summary> | |
/// Finds the <see cref="VectorPathDataResource"/> resource in input layer resources. | |
/// </summary> | |
/// <param name="psdLayer">The psd layer.</param> | |
/// <param name="createIfNotExist">If resource not exists, then for <see cref="true"/> creates a new resource, otherwise return <see cref="null"/>.</param> | |
/// <returns>The <see cref="VectorPathDataResource"/> resource.</returns> | |
private static VectorPathDataResource FindVectorPathDataResource(Layer psdLayer, bool createIfNotExist = false) | |
{ | |
VectorPathDataResource pathResource = null; | |
foreach (var resource in psdLayer.Resources) | |
{ | |
if (resource is VectorPathDataResource) | |
{ | |
pathResource = (VectorPathDataResource)resource; | |
break; | |
} | |
} | |
if (createIfNotExist && pathResource == null) | |
{ | |
pathResource = new VmskResource(); | |
} | |
return pathResource; | |
} | |
/// <summary> | |
/// Finds the <see cref="VogkResource"/> resource in input layer resources. | |
/// </summary> | |
/// <param name="psdLayer">The psd layer.</param> | |
/// <param name="createIfNotExist">If resource not exists, then for <see cref="true"/> creates a new resource, otherwise return <see cref="null"/>.</param> | |
/// <returns>The <see cref="VogkResource"/> resource.</returns> | |
private static VogkResource FindVogkResource(Layer psdLayer, bool createIfNotExist = false) | |
{ | |
VogkResource vogkResource = null; | |
foreach (var resource in psdLayer.Resources) | |
{ | |
if (resource is VogkResource) | |
{ | |
vogkResource = (VogkResource)resource; | |
break; | |
} | |
} | |
if (createIfNotExist && vogkResource == null) | |
{ | |
vogkResource = new VogkResource(); | |
} | |
return vogkResource; | |
} | |
/// <summary> | |
/// Finds the <see cref="SoCoResource"/> resource in input layer resources. | |
/// </summary> | |
/// <param name="psdLayer">The psd layer.</param> | |
/// <param name="createIfNotExist">If resource not exists, then for <see cref="true"/> creates a new resource, otherwise return <see cref="null"/>.</param> | |
/// <returns>The <see cref="SoCoResource"/> resource.</returns> | |
private static SoCoResource FindSoCoResource(Layer psdLayer, bool createIfNotExist = false) | |
{ | |
SoCoResource socoResource = null; | |
foreach (var resource in psdLayer.Resources) | |
{ | |
if (resource is SoCoResource) | |
{ | |
socoResource = (SoCoResource)resource; | |
break; | |
} | |
} | |
if (createIfNotExist && socoResource == null) | |
{ | |
socoResource = new SoCoResource(); | |
} | |
return socoResource; | |
} | |
/// <summary> | |
/// Validates the layer to work with <see cref="VectorDataProvider"/> class. | |
/// </summary> | |
/// <param name="layer"></param> | |
/// <exception cref="ArgumentNullException"></exception> | |
private static void ValidateLayer(Layer layer) | |
{ | |
if (layer == null) | |
{ | |
throw new ArgumentNullException("The layer is NULL."); | |
} | |
if (layer.Container == null || layer.Container.Size.IsEmpty) | |
{ | |
throw new ArgumentNullException("The layer should have a Container with no empty size."); | |
} | |
} | |
} | |
/// <summary> | |
/// The Bezier curve knot, it contains one anchor point and two control points. | |
/// </summary> | |
public class BezierKnot | |
{ | |
/// <summary> | |
/// Image to path point ratio. | |
/// </summary> | |
private const int ImgToPsdRatio = 256 * 65535; | |
/// <summary> | |
/// Initializes a new instance of the <see cref="BezierKnot" /> class. | |
/// </summary> | |
/// <param name="anchorPoint">The anchor point.</param> | |
/// <param name="controlPoint1">The first control point.</param> | |
/// <param name="controlPoint2">THe second control point.</param> | |
/// <param name="isLinked">The value indicating whether this knot is linked.</param> | |
public BezierKnot(PointF anchorPoint, PointF controlPoint1, PointF controlPoint2, bool isLinked) | |
{ | |
this.AnchorPoint = anchorPoint; | |
this.ControlPoint1 = controlPoint1; | |
this.ControlPoint2 = controlPoint2; | |
this.IsLinked = isLinked; | |
} | |
/// <summary> | |
/// Initializes a new instance of the <see cref="BezierKnot" /> class based on <see cref="BezierKnotRecord"/>. | |
/// </summary> | |
/// <param name="bezierKnotRecord">The <see cref="BezierKnotRecord"/>.</param> | |
/// <param name="imageSize">The image size to correct converting point coordinates.</param> | |
public BezierKnot(BezierKnotRecord bezierKnotRecord, Size imageSize) | |
{ | |
this.IsLinked = bezierKnotRecord.IsLinked; | |
this.ControlPoint1 = ResourcePointToPointF(bezierKnotRecord.Points[0], imageSize); | |
this.AnchorPoint = ResourcePointToPointF(bezierKnotRecord.Points[1], imageSize); | |
this.ControlPoint2 = ResourcePointToPointF(bezierKnotRecord.Points[2], imageSize); | |
} | |
/// <summary> | |
/// Initializes a new instance of the <see cref="BezierKnot" /> class. | |
/// </summary> | |
/// <param name="anchorPoint">The point to be anchor and control points.</param> | |
/// <param name="isLinked">The value indicating whether this knot is linked.</param> | |
public BezierKnot(PointF anchorPoint, bool isLinked) | |
: this(anchorPoint, anchorPoint, anchorPoint, isLinked) | |
{ | |
} | |
/// <summary> | |
/// Gets or sets a value indicating whether this instance is linked. | |
/// </summary> | |
public bool IsLinked { get; set; } | |
/// <summary> | |
/// Gets or sets the first control point. | |
/// </summary> | |
public PointF ControlPoint1 { get; set; } | |
/// <summary> | |
/// Gets or sets the anchor point. | |
/// </summary> | |
public PointF AnchorPoint { get; set; } | |
/// <summary> | |
/// Gets or sets the second control point. | |
/// </summary> | |
public PointF ControlPoint2 { get; set; } | |
/// <summary> | |
/// Creates the instance of <see cref="BezierKnotRecord"/> based on this instance. | |
/// </summary> | |
/// <param name="isClosed">Indicating whether this knot is in closed shape.</param> | |
/// <param name="imageSize">The image size to correct converting point coordinates.</param> | |
/// <returns>The instance of <see cref="BezierKnotRecord"/> based on this instance.</returns> | |
public BezierKnotRecord ToBezierKnotRecord(bool isClosed, Size imageSize) | |
{ | |
BezierKnotRecord record = new BezierKnotRecord(); | |
record.Points = new Point[] | |
{ | |
PointFToResourcePoint(this.ControlPoint1, imageSize), | |
PointFToResourcePoint(this.AnchorPoint, imageSize), | |
PointFToResourcePoint(this.ControlPoint2, imageSize), | |
}; | |
record.IsLinked = this.IsLinked; | |
record.IsClosed = isClosed; | |
return record; | |
} | |
/// <summary> | |
/// Shifts this knot points by input values. | |
/// </summary> | |
/// <param name="xOffset">The x offset.</param> | |
/// <param name="yOffset">The y offset.</param> | |
public void Shift(float xOffset, float yOffset) | |
{ | |
this.ControlPoint1 = new PointF(this.ControlPoint1.X + xOffset, this.ControlPoint1.Y + yOffset); | |
this.AnchorPoint = new PointF(this.AnchorPoint.X + xOffset, this.AnchorPoint.Y + yOffset); | |
this.ControlPoint2 = new PointF(this.ControlPoint2.X + xOffset, this.ControlPoint2.Y + yOffset); | |
} | |
/// <summary> | |
/// Converts point values from resource to normal. | |
/// </summary> | |
/// <param name="point">The point with values from resource.</param> | |
/// <param name="imageSize">The image size to correct converting point coordinates.</param> | |
/// <returns>The converted to normal point.</returns> | |
private static PointF ResourcePointToPointF(Point point, Size imageSize) | |
{ | |
return new PointF(point.Y / (ImgToPsdRatio / imageSize.Width), point.X / (ImgToPsdRatio / imageSize.Height)); | |
} | |
/// <summary> | |
/// Converts normal point values to resource point. | |
/// </summary> | |
/// <param name="point">The point.</param> | |
/// <param name="imageSize">The image size to correct converting point coordinates.</param> | |
/// <returns>The point with values for resource.</returns> | |
private static Point PointFToResourcePoint(PointF point, Size imageSize) | |
{ | |
return new Point((int)Math.Round(point.Y * (ImgToPsdRatio / imageSize.Height)), (int)Math.Round(point.X * (ImgToPsdRatio / imageSize.Width))); | |
} | |
} | |
/// <summary> | |
/// The figure from the knots of the Bezier curve. | |
/// </summary> | |
public class PathShape | |
{ | |
/// <summary> | |
/// Initializes a new instance of the <see cref="PathShape" /> class. | |
/// </summary> | |
public PathShape() | |
{ | |
this.Points = new List<BezierKnot>(); | |
this.PathOperations = PathOperations.CombineShapes; | |
} | |
/// <summary> | |
/// Initializes a new instance of the <see cref="PathShape" /> class based on <see cref="VectorPathRecord"/>'s. | |
/// </summary> | |
/// <param name="lengthRecord">The length record.</param> | |
/// <param name="bezierKnotRecords">The bezier knot records.</param> | |
/// <param name="imageSize">The image size to correct converting point coordinates.</param> | |
public PathShape(LengthRecord lengthRecord, List<BezierKnotRecord> bezierKnotRecords, Size imageSize) | |
: this() | |
{ | |
this.IsClosed = lengthRecord.IsClosed; | |
this.PathOperations = lengthRecord.PathOperations; | |
this.ShapeIndex = lengthRecord.ShapeIndex; | |
this.InitFromResources(bezierKnotRecords, imageSize); | |
} | |
/// <summary> | |
/// Gets or sets a value indicating whether this instance is closed. | |
/// </summary> | |
/// <value> | |
/// <c>true</c> if this instance is closed; otherwise, <c>false</c>. | |
/// </value> | |
public bool IsClosed { get; set; } | |
/// <summary> | |
/// Gets or sets the path operations (Boolean operations). | |
/// </summary> | |
public PathOperations PathOperations { get; set; } | |
/// <summary> | |
/// Gets or sets the index of current path shape in layer. | |
/// </summary> | |
public ushort ShapeIndex { get; set; } | |
/// <summary> | |
/// Gets the points of the Bezier curve. | |
/// </summary> | |
public List<BezierKnot> Points { get; private set; } | |
/// <summary> | |
/// Creates the <see cref="VectorPathRecord"/> records based on this instance. | |
/// </summary> | |
/// <param name="imageSize">The image size to correct converting point coordinates.</param> | |
/// <returns>Returns one <see cref="LengthRecord"/> and <see cref="BezierKnotRecord"/> for each point in this instance.</returns> | |
public IEnumerable<VectorPathRecord> ToVectorPathRecords(Size imageSize) | |
{ | |
List<VectorPathRecord> shapeRecords = new List<VectorPathRecord>(); | |
LengthRecord lengthRecord = new LengthRecord(); | |
lengthRecord.IsClosed = this.IsClosed; | |
lengthRecord.BezierKnotRecordsCount = this.Points.Count; | |
lengthRecord.PathOperations = this.PathOperations; | |
lengthRecord.ShapeIndex = this.ShapeIndex; | |
shapeRecords.Add(lengthRecord); | |
foreach (var bezierKnot in this.Points) | |
{ | |
shapeRecords.Add(bezierKnot.ToBezierKnotRecord(this.IsClosed, imageSize)); | |
} | |
return shapeRecords; | |
} | |
/// <summary> | |
/// Initializes a values based on input records. | |
/// </summary> | |
/// <param name="bezierKnotRecords">The bezier knot records.</param> | |
/// <param name="imageSize">The image size to correct converting point coordinates.</param> | |
private void InitFromResources(IEnumerable<BezierKnotRecord> bezierKnotRecords, Size imageSize) | |
{ | |
List<BezierKnot> newPoints = new List<BezierKnot>(); | |
foreach (var record in bezierKnotRecords) | |
{ | |
newPoints.Add(new BezierKnot(record, imageSize)); | |
} | |
this.Points = newPoints; | |
} | |
} | |
/// <summary> | |
/// The class that contains vector paths. | |
/// </summary> | |
public class VectorPath | |
{ | |
/// <summary> | |
/// Initializes a new instance of the <see cref="VectorPath" /> class based on <see cref="VectorPathDataResource"/>. | |
/// </summary> | |
/// <param name="vectorPathDataResource">The vector path data resource.</param> | |
/// <param name="imageSize">The image size to correct converting point coordinates.</param> | |
public VectorPath(VectorPathDataResource vectorPathDataResource, Size imageSize) | |
{ | |
this.InitFromResource(vectorPathDataResource, imageSize); | |
} | |
/// <summary> | |
/// Gets or sets a value indicating whether is fill starts with all pixels. | |
/// </summary> | |
/// <value> | |
/// The is fill starts with all pixels. | |
/// </value> | |
public bool IsFillStartsWithAllPixels { get; set; } | |
/// <summary> | |
/// Gets the vector shapes. | |
/// </summary> | |
public List<PathShape> Shapes { get; private set; } | |
/// <summary> | |
/// Gets or sets the vector path fill color. | |
/// </summary> | |
public Color FillColor { get; set; } | |
/// <summary> | |
/// Gets or sets the version. | |
/// </summary> | |
/// <value> | |
/// The version. | |
/// </value> | |
public int Version { get; set; } | |
/// <summary> | |
/// Gets or sets a value indicating whether this instance is disabled. | |
/// </summary> | |
/// <value> | |
/// <c>true</c> if this instance is disabled; otherwise, <c>false</c>. | |
/// </value> | |
public bool IsDisabled { get; set; } | |
/// <summary> | |
/// Gets or sets a value indicating whether this instance is not linked. | |
/// </summary> | |
/// <value> | |
/// <c>true</c> if this instance is not linked; otherwise, <c>false</c>. | |
/// </value> | |
public bool IsNotLinked { get; set; } | |
/// <summary> | |
/// Gets or sets a value indicating whether this instance is inverted. | |
/// </summary> | |
/// <value> | |
/// <c>true</c> if this instance is inverted; otherwise, <c>false</c>. | |
/// </value> | |
public bool IsInverted { get; set; } | |
/// <summary> | |
/// Initializes a values based on input <see cref="VectorPathDataResource"/> resource. | |
/// </summary> | |
/// <param name="resource">The vector path data resource.</param> | |
/// <param name="imageSize">The image size to correct converting point coordinates.</param> | |
private void InitFromResource(VectorPathDataResource resource, Size imageSize) | |
{ | |
List<PathShape> newShapes = new List<PathShape>(); | |
InitialFillRuleRecord initialFillRuleRecord = null; | |
LengthRecord lengthRecord = null; | |
List<BezierKnotRecord> bezierKnotRecords = new List<BezierKnotRecord>(); | |
foreach (var pathRecord in resource.Paths) | |
{ | |
if (pathRecord is LengthRecord) | |
{ | |
if (bezierKnotRecords.Count > 0) | |
{ | |
newShapes.Add(new PathShape(lengthRecord, bezierKnotRecords, imageSize)); | |
lengthRecord = null; | |
bezierKnotRecords.Clear(); | |
} | |
lengthRecord = (LengthRecord)pathRecord; | |
} | |
else if (pathRecord is BezierKnotRecord) | |
{ | |
bezierKnotRecords.Add((BezierKnotRecord)pathRecord); | |
} | |
else if (pathRecord is InitialFillRuleRecord) | |
{ | |
initialFillRuleRecord = (InitialFillRuleRecord)pathRecord; | |
} | |
} | |
if (bezierKnotRecords.Count > 0) | |
{ | |
newShapes.Add(new PathShape(lengthRecord, bezierKnotRecords, imageSize)); | |
lengthRecord = null; | |
bezierKnotRecords.Clear(); | |
} | |
this.IsFillStartsWithAllPixels = initialFillRuleRecord != null ? initialFillRuleRecord.IsFillStartsWithAllPixels : false; | |
this.Shapes = newShapes; | |
this.Version = resource.Version; | |
this.IsNotLinked = resource.IsNotLinked; | |
this.IsDisabled = resource.IsDisabled; | |
this.IsInverted = resource.IsInverted; | |
} | |
} | |
#endregion |