---
title: "Convert Clipping Path To Mask"
canonical: https://www.graphicsmill.com/samples/Metadata/ClippingPath/ConvertClippingPathToMask_cs
product: "Graphics Mill"
source: "Metadata/ClippingPath/ConvertClippingPathToMask.cs"
---

# Convert Clipping Path To Mask

Converts clipping path to alpha channel mask.

## Instruction

Convert a clipping path from an image into an alpha mask and save the result.

## Usings

```csharp
using Aurigma.GraphicsMill.Codecs;
using Aurigma.GraphicsMill.Drawing;
```

## Code Snippet

```csharp
using (var reader = new JpegReader("Apple.jpg"))
using (var bitmap = reader.Frames[0].GetBitmap())
using (var maskBitmap = new Bitmap(bitmap.Width, bitmap.Height, PixelFormat.Format8bppGrayscale, new GrayscaleColor(0)))
using (var graphics = maskBitmap.GetGraphics())
{
    var graphicsPath = reader.ClippingPaths[0].CreateGraphicsPath(reader.Width, reader.Height);

    graphics.FillPath(new SolidBrush(new GrayscaleColor(255)), Path.Create(graphicsPath));

    bitmap.Channels.SetAlpha(maskBitmap);

    bitmap.Save("ConvertClippingPathToMask.png");
}
```

## Explanation

The code:

- Reads a JPEG image and extracts its first frame.
- Creates an empty mask bitmap with a grayscale format.
- Uses the clipping path from the image to fill the mask bitmap with white color where the path exists.
- Sets the mask bitmap as the alpha channel of the original image.
- Saves the resulting image with the applied mask as a PNG file.

## Tags

- [Channels](<https://www.graphicsmill.com/samples/tags/channels_md>): Reading and combining image channels
- [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
- [Metadata](<https://www.graphicsmill.com/samples/tags/metadata_md>): Reading and writing image metadata

## Input

- [Apple.jpg](<https://www.graphicsmill.com/samples/Metadata/compiled/Debug/Apple_jpg>) (preview)

## Output

- [ConvertClippingPathToMask.png](<https://www.graphicsmill.com/samples/Metadata/compiled/Debug/ConvertClippingPathToMask_png>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Bitmap.Channels](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Bitmap_Channels.htm.md>)
- [Aurigma.GraphicsMill.Bitmap.GetGraphics](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Bitmap_GetGraphics.htm.md>)
- [Aurigma.GraphicsMill.ChannelsProvider.SetAlpha(Bitmap)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_ChannelsProvider_SetAlpha_1_fd4033ef.htm.md>)
- [Aurigma.GraphicsMill.Codecs.ClippingPath.Path.CreateGraphicsPath(Int32,Int32)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_ClippingPath_Path_CreateGraphicsPath_2_22dcb54d.htm.md>)
- [Aurigma.GraphicsMill.Codecs.Frame.GetBitmap](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_Frame_GetBitmap.htm.md>)
- [Aurigma.GraphicsMill.Codecs.ImageReader.ClippingPaths](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_ImageReader_ClippingPaths.htm.md>)
- [Aurigma.GraphicsMill.Codecs.ImageReader.Frames](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_ImageReader_Frames.htm.md>)
- [Aurigma.GraphicsMill.Codecs.JpegReader](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_JpegReader.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.Path](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_Path.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Path.Create(GraphicsPath)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Path_Create_1_2bc0c98a.htm.md>)
- [Aurigma.GraphicsMill.Drawing.SolidBrush](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_SolidBrush.htm.md>)
- [Aurigma.GraphicsMill.GrayscaleColor](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_GrayscaleColor.htm.md>)
