---
title: "Create Clipping Path"
canonical: https://www.graphicsmill.com/samples/Metadata/ClippingPath/CreatePath_cs
product: "Graphics Mill"
source: "Metadata/ClippingPath/CreatePath.cs"
---

# Create Clipping Path

Demonstrates how to create Adobe resource block with path from SVG file and save it to JPEG format.

## Instruction

Demonstrates how to create an Adobe resource block with a path from an SVG file and save it to a JPEG format.

## Usings

```csharp
using System;
using System.ComponentModel;
using System.Linq;
using Aurigma.GraphicsMill.Codecs;
using Aurigma.GraphicsMill.Drawing;
```

## Code Snippet

```csharp
// Internally a shape may be presented in many different ways, so we need to do this processing.
public static void CombineShapes(GraphicsContainer container, Path accumulatePath)
{
    foreach (var shapeItem in container.Items.OfType<ShapeItem>())
    {
        shapeItem.Path.ApplyTransform(shapeItem.Transform);
        accumulatePath.DrawPath(shapeItem.Path);
    }

    foreach (var containerItem in container.Items.OfType<ContainerItem>())
    {
        CombineShapes(containerItem.GraphicsContainer, accumulatePath);
    }
}

public static void Run()
{
    using (var reader = new SvgReader("cat.svg"))
    using (var gc = reader.GetContent())
    using (var bitmap = new Bitmap((int)gc.Width, (int)gc.Height, PixelFormat.Format24bppRgb, RgbColor.White))
    using (var gr = bitmap.GetGraphics())
    using (var shape = new Path())
    {
        // Read a path from the SVG file
        CombineShapes(gc, shape);

        // https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/
        const int pathInfoKey = 0x07D0;

        // Create an adobe resource block with image and save to the dictionary.
        var ar = new AdobeResourceDictionary();
        var arb = AdobeResourceBlock.CreatePath(shape, bitmap.Width, bitmap.Height);

        ar.Add(pathInfoKey, new AdobeResourceBlock("Path name", arb));

        // Draw the path we got on the bitmap.
        gr.FillPath(new SolidBrush(RgbColor.Black), shape);

        // Save the output
        bitmap.Save("cat.jpg", new JpegSettings() { AdobeResources = ar });
    }
}
```

## Explanation

The code:

- Reads an SVG file and extracts its content using `SvgReader`.
- Combines shapes from the SVG into a single path.
- Creates an Adobe resource block that includes the combined path information.
- Draws the path onto a bitmap.
- Saves the bitmap as a JPEG file while embedding the Adobe resource block containing the path.

## Tags

- [Clipping Paths](<https://www.graphicsmill.com/samples/tags/clipping-paths_md>): Reading and writing Adobe resources clipping path
- [Drawing](<https://www.graphicsmill.com/samples/tags/drawing_md>): Drawing vector shapes and text
- [Write](<https://www.graphicsmill.com/samples/tags/write_md>): Writing images with codecs

## Input

- [cat.svg](<https://www.graphicsmill.com/samples/Metadata/compiled/Debug/cat_svg>) (preview)

## Output

- [cat.jpg](<https://www.graphicsmill.com/samples/Metadata/compiled/Debug/cat_jpg>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Bitmap.GetGraphics](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Bitmap_GetGraphics.htm.md>)
- [Aurigma.GraphicsMill.Codecs.AdobeResourceBlock](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_AdobeResourceBlock.htm.md>)
- [Aurigma.GraphicsMill.Codecs.AdobeResourceBlock.CreatePath(Path,Int32,Int32)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_AdobeResourceBlock_CreatePath_3_f7f227f3.htm.md>)
- [Aurigma.GraphicsMill.Codecs.AdobeResourceDictionary](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_AdobeResourceDictionary.htm.md>)
- [Aurigma.GraphicsMill.Codecs.JpegSettings](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_JpegSettings.htm.md>)
- [Aurigma.GraphicsMill.Codecs.JpegSettings.AdobeResources](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_JpegSettings_AdobeResources.htm.md>)
- [Aurigma.GraphicsMill.Codecs.MetadataDictionary.Add(Object,Object)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_MetadataDictionary_Add_2_df764941.htm.md>)
- [Aurigma.GraphicsMill.Codecs.SvgReader](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_SvgReader.htm.md>)
- [Aurigma.GraphicsMill.Codecs.SvgReader.GetContent](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_SvgReader_GetContent.htm.md>)
- [Aurigma.GraphicsMill.Drawing.ContainerItem](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_ContainerItem.htm.md>)
- [Aurigma.GraphicsMill.Drawing.ContainerItem.GraphicsContainer](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_ContainerItem_GraphicsContainer.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.FillPath(Brush,Path)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_FillPath_2_3cee1596.htm.md>)
- [Aurigma.GraphicsMill.Drawing.GraphicsContainer](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_GraphicsContainer.htm.md>)
- [Aurigma.GraphicsMill.Drawing.GraphicsContainer.Items](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_GraphicsContainer_Items.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Item.Transform](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Item_Transform.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Path](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_Path.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Path.ApplyTransform(Matrix)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Path_ApplyTransform_1_5bff9483.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Path.DrawPath(Path)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Path_DrawPath_1_6209a3bf.htm.md>)
- [Aurigma.GraphicsMill.Drawing.ShapeItem](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_ShapeItem.htm.md>)
- [Aurigma.GraphicsMill.Drawing.ShapeItem.Path](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_ShapeItem_Path.htm.md>)
- [Aurigma.GraphicsMill.Drawing.SolidBrush](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_SolidBrush.htm.md>)
