---
title: "Preserve Color Profile And Metadata (System.Drawing Interop)"
canonical: https://www.graphicsmill.com/samples/Interoperability/SystemDrawingInteroperability/PreserveColorProfileAndMetadata_cs
product: "Graphics Mill"
source: "Interoperability/SystemDrawingInteroperability/PreserveColorProfileAndMetadata.cs"
---

# Preserve Color Profile And Metadata (System.Drawing Interop)

Converts Aurigma.GraphicsMill.Bitmap to System.Drawing.Bitmap and vice versa preserving metadata.

## Instruction

Write a C# program that demonstrates interoperability between Aurigma.GraphicsMill.Bitmap and System.Drawing.Bitmap while preserving color profile and metadata by loading JPEG via JpegReader, casting GraphicsMill Bitmap to System.Drawing.Bitmap for legacy processing (watermark application), casting back to GraphicsMill Bitmap, manually copying ColorProfile, and copying all metadata (EXIF, IPTC, XMP, AdobeResources) to JpegWriter before saving via Pipeline to maintain image integrity during format transitions.

## Usings

```csharp
using Aurigma.GraphicsMill.Codecs;
```

## Code Snippet

```csharp
// Imagine that you have a legacy application which works with System.Drawing.Bitmap,
// and you want to integrate it with Graphics Mill, and you want to preserve metadata and color profile
using (var reader = new JpegReader("Copenhagen_RGB.jpg"))
using (var gmBitmap1 = reader.Frames[0].GetBitmap())
using (var sdBitmap = (System.Drawing.Bitmap)gmBitmap1)
{
    // Here we modify System.Drawing.Bitmap
    Utils.ApplyWatermark(sdBitmap);

    // To copy pixels, just cast your System.Drawing.Bitmap to Aurigma.GraphicsMill.Bitmap.
    using (var gmBitmap2 = (Bitmap)sdBitmap)
    {
        // Copy color profile
        gmBitmap2.ColorProfile = gmBitmap1.ColorProfile;

        using (var writer = new JpegWriter("PreserveColorProfileAndMetadata.jpg"))
        {
            // Copy metadata
            writer.Exif = reader.Exif;
            writer.Iptc = reader.Iptc;
            writer.Xmp = reader.Xmp;
            writer.AdobeResources = reader.AdobeResources;

            Pipeline.Run(gmBitmap2 + writer);
        }
    }
}
```

## Explanation

Below is a C# code sample that shows System.Drawing interop with metadata preservation:

The code demonstrates seamless integration between GraphicsMill and legacy System.Drawing applications by direct casting between Bitmap types to preserve pixel data without copying, manually transferring ColorProfile after round-trip processing, and explicitly copying comprehensive metadata sets (EXIF, IPTC, XMP, AdobeResources) to JpegWriter. This pattern enables integration with existing System.Drawing-based watermarking or effects libraries while maintaining professional image quality, color accuracy via ICC profiles, and complete metadata preservation essential for photography and publishing workflows.

## Tags

- [Bitmap](<https://www.graphicsmill.com/samples/tags/bitmap_md>): Working with images via the Bitmap API
- [Color Profile](<https://www.graphicsmill.com/samples/tags/color-profile_md>): Using ICC color profiles
- [Interoperability](<https://www.graphicsmill.com/samples/tags/interoperability_md>): Interop with GDI+ and other libraries
- [Metadata](<https://www.graphicsmill.com/samples/tags/metadata_md>): Reading and writing image metadata

## Input

- [Copenhagen\_RGB.jpg](<https://www.graphicsmill.com/samples/Interoperability/compiled/Debug/Copenhagen_RGB_jpg>) (preview)

## Output

- [PreserveColorProfileAndMetadata.jpg](<https://www.graphicsmill.com/samples/Interoperability/compiled/Debug/PreserveColorProfileAndMetadata_jpg>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Bitmap.ColorProfile](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Bitmap_ColorProfile.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.AdobeResources](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_ImageReader_AdobeResources.htm.md>)
- [Aurigma.GraphicsMill.Codecs.ImageReader.Exif](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_ImageReader_Exif.htm.md>)
- [Aurigma.GraphicsMill.Codecs.ImageReader.Frames](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_ImageReader_Frames.htm.md>)
- [Aurigma.GraphicsMill.Codecs.ImageReader.Iptc](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_ImageReader_Iptc.htm.md>)
- [Aurigma.GraphicsMill.Codecs.ImageReader.Xmp](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_ImageReader_Xmp.htm.md>)
- [Aurigma.GraphicsMill.Codecs.JpegReader](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_JpegReader.htm.md>)
- [Aurigma.GraphicsMill.Codecs.JpegWriter](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_JpegWriter.htm.md>)
- [Aurigma.GraphicsMill.Codecs.JpegWriter.AdobeResources](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_JpegWriter_AdobeResources.htm.md>)
- [Aurigma.GraphicsMill.Codecs.JpegWriter.Exif](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_JpegWriter_Exif.htm.md>)
- [Aurigma.GraphicsMill.Codecs.JpegWriter.Iptc](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_JpegWriter_Iptc.htm.md>)
- [Aurigma.GraphicsMill.Codecs.JpegWriter.Xmp](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_JpegWriter_Xmp.htm.md>)
