What's New in Documents for Imaging v2
GcImaging v2
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 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
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.
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.
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);
}
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);
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.
See more details here:
var bmp = new GcBitmap("BeforeAutoLevel.jpg");
bmp.AutoLevel();
bmp.SaveAsJpeg("AfterAutoLevel.jpg");
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);
}