---
title: "Modify Clipping Path Explicitly"
canonical: https://www.graphicsmill.com/samples/Metadata/ClippingPath/ModifyClippingPathExplicitly_cs
product: "Graphics Mill"
source: "Metadata/ClippingPath/ModifyClippingPathExplicitly.cs"
---

# Modify Clipping Path Explicitly

Modifies clipping path explicitly.

## Instruction

Crop the image while modifying its clipping path explicitly and save the result as a JPEG file.

## Usings

```csharp
using Aurigma.GraphicsMill.Codecs;
using Aurigma.GraphicsMill.Transforms;
```

## Code Snippet

```csharp
using (var reader = new JpegReader("Apple.jpg"))
using (var bitmap = reader.Frames[0].GetBitmap())
{
    var crop = new Crop(20, 20, bitmap.Width - 40, bitmap.Height - 40);

    var cropped = crop.Apply(bitmap);

    var clippingPath = reader.ClippingPaths[0];

    clippingPath.ApplyTransform(crop.GetPathTransformMatrix(bitmap.Width, bitmap.Height).ToGdiPlusMatrix());

    var adobeResources = new AdobeResourceDictionary();
    adobeResources.Add(FirstPathId, new AdobeResourceBlock("Apple", clippingPath.Data));

    var jpegSettings = new JpegSettings();
    jpegSettings.AdobeResources = adobeResources;

    cropped.Save("ModifyClippingPathExplicitly.jpg", jpegSettings);
}
```

## Explanation

The code:

- Reads the "Apple.jpg" image and extracts its first frame.
- Crops the image using specified coordinates (20, 20) to (bitmap.Width - 40, bitmap.Height - 40).
- Modifies the clipping path associated with the image by applying the crop transformation.
- Creates an Adobe resource dictionary and adds the modified clipping path to it.
- Saves the cropped image with the updated clipping path to "ModifyClippingPathExplicitly.jpg" with the Adobe resources (clipping path) included.

## Tags

- [Bitmap](<https://www.graphicsmill.com/samples/tags/bitmap_md>): Working with images via the Bitmap API
- [Clipping Paths](<https://www.graphicsmill.com/samples/tags/clipping-paths_md>): Reading and writing Adobe resources clipping path
- [Crop](<https://www.graphicsmill.com/samples/tags/crop_md>): Cropping images
- [Read](<https://www.graphicsmill.com/samples/tags/read_md>): Reading images with codecs
- [Write](<https://www.graphicsmill.com/samples/tags/write_md>): Writing images with codecs

## Input

- [Apple.jpg](<https://www.graphicsmill.com/samples/Metadata/compiled/Debug/Apple_jpg>) (preview)

## Output

- [ModifyClippingPathExplicitly.jpg](<https://www.graphicsmill.com/samples/Metadata/compiled/Debug/ModifyClippingPathExplicitly_jpg>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Codecs.AdobeResourceBlock](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_AdobeResourceBlock.htm.md>)
- [Aurigma.GraphicsMill.Codecs.AdobeResourceDictionary](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_AdobeResourceDictionary.htm.md>)
- [Aurigma.GraphicsMill.Codecs.ClippingPath.Path.ApplyTransform(Matrix)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_ClippingPath_Path_ApplyTransform_1_5bff9483.htm.md>)
- [Aurigma.GraphicsMill.Codecs.ClippingPath.Path.Data](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_ClippingPath_Path_Data.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.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.Transforms.Crop](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_Crop.htm.md>)
- [Aurigma.GraphicsMill.Transforms.Matrix.ToGdiPlusMatrix](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Transforms_Matrix_ToGdiPlusMatrix.htm.md>)
- [Aurigma.GraphicsMill.Transforms.Transform.Apply(Bitmap)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Transforms_Transform_Apply_1_fd4033ef.htm.md>)
- [Aurigma.GraphicsMill.Transforms.Transform.GetPathTransformMatrix(Int32,Int32)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Transforms_Transform_GetPathTransformMatrix_2_22dcb54d.htm.md>)
