Process Non-RGB (System.Drawing Interop)
Interoperability Bitmap Metadata
Loads non-RGB image with Aurigma.GraphicsMill.Bitmap, pass it to System.Drawing.Bitmap and convert it back to Aurigma.GraphicsMill.Bitmap.
Сode Snippet
// Imagine that you have a legacy application which works with System.Drawing.Bitmap,
// and you need to work with non-RGB images. You should convert it to RGB with Graphics Mill, cast it
// to System.Drawing.Bitmap and convert back.
using (var reader = new JpegReader("Copenhagen_CMYK.jpg"))
using (var gmBitmap1 = reader.Frames[0].GetBitmap())
{
Bitmap rgbGmBitmap = null;
try
{
// Convert a non-RGB image to the RGB color space with the sRGB color profile
if (!gmBitmap1.PixelFormat.IsRgb)
{
rgbGmBitmap = new Bitmap(gmBitmap1);
rgbGmBitmap.ColorManagement.DestinationProfile = ColorProfile.FromSrgb();
rgbGmBitmap.ColorManagement.Convert(PixelFormat.Format24bppRgb);
}
using (var sdBitmap = (System.Drawing.Bitmap)(gmBitmap1.PixelFormat.IsRgb ? gmBitmap1 : rgbGmBitmap))
{
// Here we modify System.Drawing.Bitmap
Utils.ApplyWatermark(sdBitmap);
using (var gmBitmap2 = (Bitmap)sdBitmap)
{
// Convert an RGB image to the source color space (CMYK, grayscale, or Lab)
if (!gmBitmap1.PixelFormat.IsRgb)
{
gmBitmap2.ColorProfile = ColorProfile.FromSrgb();
gmBitmap2.ColorManagement.DestinationProfile = gmBitmap1.ColorProfile;
gmBitmap2.ColorManagement.Convert(gmBitmap1.PixelFormat);
}
// Copy color profile
gmBitmap2.ColorProfile = gmBitmap1.ColorProfile;
using (var writer = new JpegWriter("ProcessNonRgb.jpg"))
{
// Copy metadata
writer.Exif = reader.Exif;
writer.Iptc = reader.Iptc;
writer.Xmp = reader.Xmp;
writer.AdobeResources = reader.AdobeResources;
Pipeline.Run(gmBitmap2 + writer);
}
}
}
}
finally
{
if (rgbGmBitmap != null)
{
rgbGmBitmap.Dispose();
}
}
}
Input
Copenhagen_CMYK.jpg
Output
ProcessNonRgb.jpg
For AI-assisted development: Download Graphics Mill Code Samples XML Catalog