/// <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>
            /// 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);
            }
コード例 #3
0
        public static PsdShape[] GetShapes(this Layer layer)
        {
            VectorMaskSetting setting = layer.GetVectorMaskSetting();

            if (setting == null)
            {
                return(null);
            }

            List <PsdShape> result = new List <PsdShape>();

            Vector2[] points     = null;
            int       pointIndex = 0;
            bool      isClosed   = false;

            foreach (var record in setting.PathDataRecords)
            {
                if (record is SubpathLengthRecord)
                {
                    SubpathLengthRecord lengthRecord = record as SubpathLengthRecord;
                    if (points != null)
                    {
                        throw new PsdInvalidException("Duplicate subpath length record");
                    }

                    points     = new Vector2[lengthRecord.BezierKnotCount];
                    pointIndex = 0;
                    isClosed   = lengthRecord.IsClosed;
                }
                else if (record is BezierKnotRecord)
                {
                    BezierKnotRecord knowRecord = record as BezierKnotRecord;
                    points[pointIndex++] = new Vector2(knowRecord.AnchorPoint.Horizontal, knowRecord.AnchorPoint.Vertical);
                    if (pointIndex == points.Length)
                    {
                        result.Add(new PsdShape(points, isClosed));
                        points     = null;
                        pointIndex = 0;
                    }
                }
            }
            return(result.ToArray());
        }
コード例 #4
0
        public static void Run()
        {
            string baseFolder   = RunExamples.GetDataDir_PSD();
            string outputFolder = RunExamples.GetDataDir_Output();

            //ExStart:SupportOfWorkingPathResource
            //ExSummary:This example demonstrates the support of 'WorkingPathResource' resource in PsdImage.ImageResources fo correct working of Crop operation.

            string sourceFile = Path.Combine(baseFolder, "WorkingPathResourceInput.psd");
            string outputFile = Path.Combine(outputFolder, "WorkingPathResourceOutput.psd");

            // Crop image and save.
            using (var psdImage = (PsdImage)Image.Load(sourceFile))
            {
                // Search WorkingPathResource resource.
                ResourceBlock[]     imageResources      = psdImage.ImageResources;
                WorkingPathResource workingPathResource = null;
                foreach (var imageResource in imageResources)
                {
                    if (imageResource is WorkingPathResource)
                    {
                        workingPathResource = (WorkingPathResource)imageResource;
                        break;
                    }
                }
                BezierKnotRecord record = workingPathResource.Paths[3] as BezierKnotRecord;

                if (record.Points[0].X != 2572506 || record.Points[0].Y != 8535408)
                {
                    throw new Exception("Values is incorrect.");
                }

                // Crop and save.
                psdImage.Crop(0, 500, 0, 200);
                psdImage.Save(outputFile);
            }

            // Load saved image and check the changes.
            using (var psdImage = (PsdImage)Image.Load(outputFile))
            {
                // Search WorkingPathResource resource.
                ResourceBlock[]     imageResources      = psdImage.ImageResources;
                WorkingPathResource workingPathResource = null;
                foreach (var imageResource in imageResources)
                {
                    if (imageResource is WorkingPathResource)
                    {
                        workingPathResource = (WorkingPathResource)imageResource;
                        break;
                    }
                }
                BezierKnotRecord record = workingPathResource.Paths[3] as BezierKnotRecord;

                if (record.Points[0].X != 4630510 || record.Points[0].Y != 22761088)
                {
                    throw new Exception("Values is incorrect.");
                }
            }

            //ExEnd:SupportOfWorkingPathResource

            Console.WriteLine("SupportOfWorkingPathResource executed successfully");
        }