Preserve Color Profile And Metadata (System.Drawing Interop)

Interoperability Bitmap Metadata Color Profile

Converts Aurigma.GraphicsMill.Bitmap to System.Drawing.Bitmap and vice versa preserving metadata.

Сode Snippet

// 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);
        }
    }
}

Input

Copenhagen_RGB.jpg

Output

PreserveColorProfileAndMetadata.jpg

For AI-assisted development: Download Graphics Mill Code Samples XML Catalog