/// <summary>
    /// Converts Aurigma.GraphicsMill.Bitmap to System.Drawing.Bitmap and vice versa preserving metadata
    /// </summary>
    private static void PreserveColorProfileAndMetadata()
    {
        // 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 Aurigma.GraphicsMill.Codecs.JpegReader("../../../../_Input/Copenhagen_RGB.jpg"))
            using (var gmBitmap1 = reader.Frames[0].GetBitmap())
                // To convert Aurigma's bitmap to System.Drawing.Bitmap, just cast it
                using (var sdBitmap = (System.Drawing.Bitmap)gmBitmap1)
                {
                    // Here we modify System.Drawing.Bitmap
                    ApplyWatermark(sdBitmap);

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

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

                            Aurigma.GraphicsMill.Pipeline.Run(gmBitmap2 + writer);
                        }
                    }
                }
    }
    /// <summary>
    /// Loads non-RGB image with Aurigma.GraphicsMill.Bitmap, pass it to System.Drawing.Bitmap and
    /// convert it back to Aurigma.GraphicsMill.Bitmap.
    /// </summary>
    private static void ProcessNonRgb()
    {
        // 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 Aurigma.GraphicsMill.Codecs.JpegReader("../../../../_Input/Copenhagen_CMYK.jpg"))
            using (var gmBitmap1 = reader.Frames[0].GetBitmap())
            {
                Aurigma.GraphicsMill.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 Aurigma.GraphicsMill.Bitmap(gmBitmap1);
                        rgbGmBitmap.ColorManagement.DestinationProfile = Aurigma.GraphicsMill.ColorProfile.FromSrgb();
                        rgbGmBitmap.ColorManagement.Convert(Aurigma.GraphicsMill.PixelFormat.Format24bppRgb);
                    }

                    using (var sdBitmap = (System.Drawing.Bitmap)(gmBitmap1.PixelFormat.IsRgb ? gmBitmap1 : rgbGmBitmap))
                    {
                        // Here we modify System.Drawing.Bitmap
                        ApplyWatermark(sdBitmap);

                        using (var gmBitmap2 = (Aurigma.GraphicsMill.Bitmap)sdBitmap)
                        {
                            // Convert an RGB image to the source color space (CMYK, grayscale, or Lab)
                            if (!gmBitmap1.PixelFormat.IsRgb)
                            {
                                gmBitmap2.ColorProfile = Aurigma.GraphicsMill.ColorProfile.FromSrgb();
                                gmBitmap2.ColorManagement.DestinationProfile = gmBitmap1.ColorProfile;
                                gmBitmap2.ColorManagement.Convert(gmBitmap1.PixelFormat);
                            }

                            // Copy color profile
                            gmBitmap2.ColorProfile = gmBitmap1.ColorProfile;

                            using (var writer = new Aurigma.GraphicsMill.Codecs.JpegWriter("../../../../_Output/ProcessNonRgb.jpg"))
                            {
                                // Copy metadata
                                writer.Exif           = reader.Exif;
                                writer.Iptc           = reader.Iptc;
                                writer.Xmp            = reader.Xmp;
                                writer.AdobeResources = reader.AdobeResources;

                                Aurigma.GraphicsMill.Pipeline.Run(gmBitmap2 + writer);
                            }
                        }
                    }
                }
                finally
                {
                    if (rgbGmBitmap != null)
                    {
                        rgbGmBitmap.Dispose();
                    }
                }
            }
    }
Beispiel #3
0
        private static Aurigma.GraphicsMill.Bitmap ExtractExifThumbnail(Aurigma.GraphicsMill.Codecs.ImageReader reader, int width, int height)
        {
            Aurigma.GraphicsMill.Codecs.ExifDictionary exif = null;
            Aurigma.GraphicsMill.Bitmap result = null;

            try
            {
                Aurigma.GraphicsMill.Codecs.JpegReader jpgReader = reader as Aurigma.GraphicsMill.Codecs.JpegReader;
                if (jpgReader != null)
                {
                    exif = jpgReader.Exif;
                }
                else
                {
                    Aurigma.GraphicsMill.Codecs.TiffReader tiffReader = reader as Aurigma.GraphicsMill.Codecs.TiffReader;
                    if (tiffReader != null)
                    {
                        exif = tiffReader.Exif;
                    }
                    else
                    {
                        Aurigma.GraphicsMill.Codecs.Psd.PsdReader psdReader = reader as Aurigma.GraphicsMill.Codecs.Psd.PsdReader;
                        if (psdReader != null)
                        {
                            exif = psdReader.Exif;
                        }
                    }
                }

                if (exif != null && exif.Contains(Aurigma.GraphicsMill.Codecs.ExifDictionary.Thumbnail))
                {
                    Aurigma.GraphicsMill.Bitmap exifThumbnail = (Aurigma.GraphicsMill.Bitmap)exif[Aurigma.GraphicsMill.Codecs.ExifDictionary.Thumbnail];
                    if (exifThumbnail.Width >= width || exifThumbnail.Height >= height)
                    {
                        exifThumbnail.Transforms.Resize(width, height, Transforms.ResizeInterpolationMode.High, Aurigma.GraphicsMill.Transforms.ResizeMode.Shrink);
                        result = exifThumbnail;
                    }
                    else
                    {
                        exifThumbnail.Dispose();
                    }
                }
            }
            catch
            {
                if (exif != null)
                {
                    exif.Dispose();
                }
                exif   = null;
                result = null;
            }

            return(result);
        }