Preserve Color Profile And Metadata (System.Drawing Interop)
View as MarkdownConverts Aurigma.GraphicsMill.Bitmap to System.Drawing.Bitmap and vice versa preserving metadata.
Code 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
Used APIs
- Aurigma.GraphicsMill.Bitmap.ColorProfile
- Aurigma.GraphicsMill.Codecs.Frame.GetBitmap
- Aurigma.GraphicsMill.Codecs.ImageReader.AdobeResources
- Aurigma.GraphicsMill.Codecs.ImageReader.Exif
- Aurigma.GraphicsMill.Codecs.ImageReader.Frames
- Aurigma.GraphicsMill.Codecs.ImageReader.Iptc
- Aurigma.GraphicsMill.Codecs.ImageReader.Xmp
- Aurigma.GraphicsMill.Codecs.JpegReader
- Aurigma.GraphicsMill.Codecs.JpegWriter
- Aurigma.GraphicsMill.Codecs.JpegWriter.AdobeResources
- Aurigma.GraphicsMill.Codecs.JpegWriter.Exif
- Aurigma.GraphicsMill.Codecs.JpegWriter.Iptc
- Aurigma.GraphicsMill.Codecs.JpegWriter.Xmp