Imaging API Hero

Documents for Imaging was introduced to the public in January of 2019 with an aim to launch an image library that can create, load, modify, and save images in .NET Core applications (with support on Windows, macOS, and Linux and deploy as FaaS with AWS Lambda, and Azure Functions.

The library is a feature-rich API that can load popular image formats like, BMP, JPEG, TIFF, GIF, and PNG. It can apply advanced image processing techniques and save them back; read/write images, modify images (like rotate, crop, and resize), convert images, apply dithering, and thresholding effects on grayscale images; apply effects on RGB images, draw and fill graphics on images, draw advanced text with full font handling, text, paragraph formatting on images, apply advanced TIFF features, and much more.

Over the last few years, there has been a need to re-color images used to suit website needs, follow specific visual styles and sizing, or to speed up the download of images. There have been various algorithms to process images, but when these images are processed and returned back through the web stream, the quality of image degrades.

The main highlight of the new GcImaging v2 sp2 is the addition of advanced algorithms to reduce color palettes in large images. This maintains the quality of the images. In addition, more features are added to the API that can help work with and combine images of multiple formats.

Read the full GcDocs release

Let's dive in.

Read and Write Multi-Frame GIF Files

The GIF file format is the most popular graphic format that supports animation. As multiple frames contribute to an animated GIF File, it will now be possible to load, modify, and save such multi-frame GIF images in GcImaging. The GcGifReader and GcGifWriter classes have been added to the API that can be used for creating multi-frame GIF files and reading separate frames from existing GIF files.

You can control following features of GIF images:

  • Height and width of Logical Screen where the frames will be rendered
  • PixelAspectRatio
  • Number of iterations the animated GIF should be executed
  • Encoding for the comment string
  • Set optional GIF comment
  • Gets or sets the palette with opaque colors
  • IccProfileData
  • Add transparent color to global/local color tables
  • Get index of the next frame
  • Set horizontal/vertical resolution
  • Append frame with various settings

Help | Demo

Combine Two Bitmaps into a Single Image

Combine two bitmaps into a single image, with addition of Porter Duff compositing and blending algorithms which compute the color result from the composite source and destination images. The CompositeMode enumeration provides options to determine the final color while combining images, while BlendingMode provides the methods of mixing the colors with the backdrop.

These are used as one of the parameters in the new GcBitmap.CompositeAndBlend(..) method, which works as a scheme for blending the overlapping parts.

Help | Demo

Convert Images to Indexed Bitmap Images with Custom Palette and New Quantiser Algorithm

GcImaging now adds another method GenerateOctreePalette that can be used together with dithering methods. This can help reduce the number of unique colors in an image while keeping the general look of the image. This is particularly helpful if image contains large number of palette colors and the size becomes larger.

The Octree Quantizer algorithm used in GcImaging API can load images of any type, regardless of the number of different colors in the image, and then generate a good quality image with little degradation when converting from a high number of colors to an image with lesser size and lower number of palette colors.

Help | Demo

New Methods to Export/Import Color Channels

Color channels of images can be modified to make creative color adjustments to an image. It would be helpful to extract the color channel, apply modifications, and then use it in single or multiple images, which need to be similarly processed. With GcImaging, you will be able to export color channels from images, apply modification for example adjust the brightness or contrast levels, and import the color channel back into the image. This method can also be used to apply similar color channel to thousands of images together.

using (var bmp = new GcBitmap())
{
    bmp.Load(TestUtil.ImagePath + "tudor.jpg");
    using (var gb = new GrayscaleBitmap(bmp.PixelWidth, bmp.PixelHeight))
    {
        bmp.ExportColorChannel(gb, ColorChannel.Red);
        gb.AdjustLevels(0, 100, 150, 250);
        bmp.ImportColorChannel(gb, ColorChannel.Red);
    }
    bmp.SaveAsJpeg(outputStream);
}

Help

ICCProfile Support for Image Types

When images are transferred from one device to another, it is necessary that images follow the ICC profile specific to the device, or in other words, use the right color to display on any device. With GcImaging, you can now embed and extract ICC Profile data of/from an image. The support has been added to JPEG, GIF, PNG, and TIFF image formats. The property exists in -Indexed4bppBitmap, Indexed8bppBitmap, GrayscaleBitmap, and BilevelBitmap type of images.

using (var bmp = new GcBitmap())
{
    // load a PNG image with ICC profile
    bmp.Load(imagePath + "eggs1cHRM.png");

    Debug.WriteLine($"ICC profile consists of {bmp.IccProfileData.Length} bytes");

    // save the image with ICC profile as Jpeg
    bmp.SaveAsJpeg(outputStream);

Help

Lightweight Image Class

The Image class will now work with images with more efficiency and less memory usage. The Image class is now lightweight and loads pixels on demand. If you need to extract the size, format or Exif metadata from an image, the Image class will be more handier and performant than GcBitmap. The image can be associated with a single frame or a multi-frame GIF or TIFF file. The ToStream() method saves the whole source (such as a multi-frame GIF or TIFF) to the output stream.

This improvement can help load multiple images of different formats from files and streams, draw images on graphics or save them as is with the Image.ToStream() method, with very less memory consumption.

New Methods for Improving the Image Histogram (AutoLevel, AdjustLevels, AutoContrast)

The new GcBitmap.AutoLevel(), GcBitmap.AdjustLevel(), and GcBitmap.AutoContrast() methods can automatically adjust the right color intensities needed for the images and distribute the tones uniformly on the image histogram, in minimal lines of code.

Before AutoLevel

 After AutoLevel

See more details here:

var bmp = new GcBitmap("BeforeAutoLevel.jpg");
bmp.AutoLevel();
bmp.SaveAsJpeg("AfterAutoLevel.jpg");

Help | Demo

Support for all MS Excel Pattern Fills in the HatchStyle Enumeration

GcImaging has been supporting certain HatchStyle patterns for creating a HatchBrush and filling regions. It now supports total 48 Hatch Styles that fill image regions.

using (var bmp = new GcBitmap(300, 200, true))
{
    using (var g = bmp.CreateGraphics(Color.White))
    {
        var b = new HatchBrush(HatchStyle.Sphere)
        {
            ForeColor = Color.Navy,
            BackColor = Color.White
        };
        g.FillRectangle(new RectangleF(0, 0, 300, 200), b);
    }
    bmp.SaveAsPng(outputStream);
}

Demo

What do you think about the new features? Leave a comment below.

Try GrapeCity Documents for Imaging v2 sp2

Download the latest version of GrapeCity Documents for Imaging

Download Now!