/// <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> /// 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; }
/// <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); }
public static void Run() { // The path to the documents directory. string SourceDir = RunExamples.GetDataDir_PSD(); string OutputDir = RunExamples.GetDataDir_Output(); //ExStart:VsmsResourceLengthRecordSupport //ExSummary:The following code example demonstrates the support of new LengthRecord properties, PathOperations (boolean operations), ShapeIndex and BezierKnotRecordsCount. string fileName = SourceDir + "PathOperationsShape.psd"; string outFileName = OutputDir + "out_PathOperationsShape.psd"; using (var im = (PsdImage)Image.Load(fileName)) { VsmsResource resource = null; foreach (var layerResource in im.Layers[1].Resources) { if (layerResource is VsmsResource) { resource = (VsmsResource)layerResource; break; } } LengthRecord lengthRecord0 = (LengthRecord)resource.Paths[2]; LengthRecord lengthRecord1 = (LengthRecord)resource.Paths[7]; LengthRecord lengthRecord2 = (LengthRecord)resource.Paths[11]; // Here we changin the way to combining betwen shapes. lengthRecord0.PathOperations = PathOperations.ExcludeOverlappingShapes; lengthRecord1.PathOperations = PathOperations.IntersectShapeAreas; lengthRecord2.PathOperations = PathOperations.SubtractFrontShape; im.Save(outFileName); } //ExEnd:SupportForClblResource Console.WriteLine("VsmsResourceLengthRecordSupport executed successfully"); }