Class PathResource

Class PathResource

Namespace: Aspose.Imaging.FileFormats.Tiff.PathResources
Assembly: Aspose.Imaging.dll (25.2.0)

Represents Photoshop Path Resource.

public class PathResource

Inheritance

objectPathResource

Inherited Members

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Examples

Transfer Clipping Paths during export from TIFF to PSD image.```csharp [C#]

                                                                    using (var image = Image.Load("Sample.tif"))
                                                                    {
                                                                        image.Save("SampleWithPaths.psd", new PsdOptions());
                                                                    }

The following example shows how to create Clipping Path in TIFF image. In order to do that you need to create an instance of PathResource class. The following code demonstrates the way how you can create an empty path in TIFF image.```csharp
[C#]

                                                                                                                                                                                                                                                   var options = new TiffOptions(TiffExpectedFormat.Default);
                                                                                                                                                                                                                                                   var frame = new TiffFrame(options, 800, 600);

                                                                                                                                                                                                                                                   using (var image = new TiffImage(frame))
                                                                                                                                                                                                                                                   {
                                                                                                                                                                                                                                                       image.ActiveFrame.PathResources = new List<pathresource>
                                                                                                                                                                                                                                                       {
                                                                                                                                                                                                                                                           new PathResource
                                                                                                                                                                                                                                                           {
                                                                                                                                                                                                                                                               BlockId = 2000,
                                                                                                                                                                                                                                                               Name = "My Clipping Path",
                                                                                                                                                                                                                                                               Records = new List<vectorpathrecord>()
                                                                                                                                                                                                                                                           }
                                                                                                                                                                                                                                                       };

                                                                                                                                                                                                                                                       image.Save("ImageWithEmptyPath.tiff");
                                                                                                                                                                                                                                                   }</vectorpathrecord></pathresource>

Create Graphics Path from Path Resources in TIFF image.```csharp [C#]

                                                              using (var image = (TiffImage)Image.Load("Bottle.tif"))
                                                              {
                                                                  // Create the GraphicsPath using PathResources from TIFF image
                                                                  var graphicsPath = PathResourceConverter.ToGraphicsPath(image.ActiveFrame.PathResources.ToArray(), image.ActiveFrame.Size);
                                                                  var graphics = new Graphics(image);

                                                                  // Draw red line and save the image
                                                                  graphics.DrawPath(new Pen(Color.Red, 10), graphicsPath);
                                                                  image.Save("BottleWithRedBorder.tif");
                                                              }

Create Path Resources using Graphics Path.```csharp
[C#]

                                                     static void Main(string[] args)
                                                     {
                                                         using (var image = (TiffImage)Image.Load("Bottle.tif"))
                                                         {
                                                             // Create rectangular Figure for GraphicsPath
                                                             var figure = new Figure();
                                                             figure.AddShape(CreateBezierShape(100f, 100f, 500f, 100f, 500f, 1000f, 100f, 1000f));

                                                             // Create GraphicsPath using our Figure
                                                             var graphicsPath = new GraphicsPath();
                                                             graphicsPath.AddFigure(figure);

                                                             // Set PathResources using GraphicsPath
                                                             var pathResouze = PathResourceConverter.FromGraphicsPath(graphicsPath, image.Size);
                                                             image.ActiveFrame.PathResources = new List<pathresource>(pathResouze);

                                                             // Save the image
                                                             image.Save("BottleWithRectanglePath.tif");
                                                         }
                                                     }

                                                     private static BezierShape CreateBezierShape(params float[] coordinates)
                                                     {
                                                         var bezierPoints = CoordinatesToBezierPoints(coordinates).ToArray();
                                                         return new BezierShape(bezierPoints, true);
                                                     }

                                                     private static IEnumerable<pointf> CoordinatesToBezierPoints(float[] coordinates)
                                                     {
                                                         for (var coordinateIndex = 0; coordinateIndex &lt; coordinates.Length; coordinateIndex += 2)
                                                             for (var index = 0; index &lt; 3; index++)
                                                                 yield return new PointF(coordinates[coordinateIndex], coordinates[coordinateIndex + 1]);
                                                     }</pointf></pathresource>

Create Clipping Path manually.```csharp [C#]

                                     static void Main()
                                     {
                                         using (var image = (TiffImage)Image.Load("Sample.tif"))
                                         {
                                             image.ActiveFrame.PathResources = new List<pathresource> { new PathResource
                                             {
                                                 BlockId = 2000,                                                          // Block Id according to Photoshop specification
                                                 Name = "My Clipping Path",                                               // Path name
                                                 Records = CreateRecords(0.2f, 0.2f, 0.8f, 0.2f, 0.8f, 0.8f, 0.2f, 0.8f)  // Create path records using coordinates
                                             }};

                                             image.Save("ImageWithPath.tif");
                                         }
                                     }

                                     private static List<vectorpathrecord> CreateRecords(params float[] coordinates)
                                     {
                                         var records = CreateBezierRecords(coordinates);                                  // Create Bezier records using coordinates

                                         records.Insert(0, new LengthRecord                                               // LengthRecord required by Photoshop specification
                                         {
                                             IsOpen = false,                                                              // Lets create closed path
                                             RecordCount = (ushort)records.Count                                          // Record count in the path
                                         });

                                         return records;
                                     }

                                     private static List<vectorpathrecord> CreateBezierRecords(float[] coordinates)
                                     {
                                         return CoordinatesToPoints(coordinates)
                                             .Select(CreateBezierRecord)
                                             .ToList();
                                     }

                                     private static IEnumerable<pointf> CoordinatesToPoints(float[] coordinates)
                                     {
                                         for (var index = 0; index &lt; coordinates.Length; index += 2)
                                             yield return new PointF(coordinates[index], coordinates[index + 1]);
                                     }

                                     private static VectorPathRecord CreateBezierRecord(PointF point)
                                     {
                                         return new BezierKnotRecord { PathPoints = new[] { point, point, point } };
                                     }</pointf></vectorpathrecord></vectorpathrecord></pathresource>

## Constructors

### <a id="Aspose_Imaging_FileFormats_Tiff_PathResources_PathResource__ctor"></a> PathResource\(\)

```csharp
public PathResource()

Properties

BlockId

Gets or sets the block identifier.

public short BlockId { get; set; }

Property Value

short

Name

Gets or sets the name.

public string Name { get; set; }

Property Value

string

Records

Gets or sets the records.

public List<vectorpathrecord> Records { get; set; }

Property Value

List<VectorPathRecord&gt;