This documentation is for the old version. Go to the latest Graphics Mill docs

PixelFormatConverter Class

This class enables you to convert a bitmap from one pixel format to another one.

Namespace: Aurigma.GraphicsMill.Transforms
Assembly: Aurigma.GraphicsMill (in Aurigma.GraphicsMill.dll)

Syntax

Visual Basic
Public NotInheritable Class PixelFormatConverter _
	Inherits BitmapTransform
C#
public sealed class PixelFormatConverter : BitmapTransform

Remarks

Using this class you can modify pixel format of the bitmap. To specify new pixel format use property DestinationPixelFormat. Pixel formats can be divided into two big groups - indexed and continuous ones. These groups has different set of settings.

Indexed pixel formats are defined in the following way: colors are stores in a special table called palette. Pixels in such images are indexes in the palette (pointing this way to the necessary color). When bit depth of this pixel format is 1 bpp (bits per pixel), the palette can contain only 2 colors, 4 bpp - 16 colors, and 8 bpp - 256 colors. When you convert the image to indexed pixel format, you should specify how to produce the palette. You can do it using PaletteType property. You also may need to specify a number of entries in the palette (the less colors number the image has, the better compression characteristics does it have).

Number of colors in the palette are closely concerned with another block of settings. When we reducing number of colors (for example, when we convert from 24 bpp image to 8 bpp, we convert 16 millions of colors to 256 ones), the colors are usually noticeable distorted. Multiple hues (halftones) of some color are converted to single colors, gradients are turned into areas filled with solid color. To decrease this effect, special technique called dithering is used. The idea is to emulate halftones by spreading pixels of the palette with different density. Human eye perceives it as a new color. There are multiple dithering algorithms are available. You can select one of them with Dithering property. You can also specify dithering intensity with DitheringIntensity property.

Continuous pixel formats are organized in another way. Pixels are constructed from one or more color channels. Each color channel contains a value that specifies this channel luminosity. A set of color channels depends on the image color space. Currently Graphics Mill for .NET supports such color spaces as RGB, CMYK, and grayscale. Conversion between color spaces is not unambiguous, and that's why colors may get distorted during conversion. To resolve this problem, color management is used. Color management is performed with a help of color profiles. Two color profiles should be defined - input profile and output profile. Input profile is always taken from the source bitmap (ColorProfile property of the Bitmap class), output profile is set for each target color space via CmykColorProfile, RgbColorProfile, and GrayScaleColorProfile correspondingly. You can also specify so-called rendering intent using TransformationIntent property. Rendering intent allows to tell the algorithm what color parameters are most important to you and what one can be discarded. If you do not care about color transformation precision and prefer higher speed, you can disable color management (set the ColorManagementEngine property to None).

Another nuance you should keep in mind is handling the situation when source pixel format had alpha channel, but the destination one - has not and vice versa. The table below describes how this problem is resolved with this class.

Has Alpha How to Resolve
Both source and destination. No specific action should be performed.
Only source. As destination pixel format has no alpha channel, we should remove alpha information from the source bitmap. We can either discard alpha channel, or emulate it by blending the source bitmap with some background color. If property BackgroundEnabled is set to true, the algorithm blends the source image with the color specified with BackgroundColor property. Otherwise alpha channel is just ignored.
Only destination. In case when source bitmap does not have alpha channel information, but we need to add it during conversion, the only thing we should know is an initial value for the alpha channel. It is specified with Opacity property.
Neither source nor destination. No specific action should be performed.

Inheritance Hierarchy

Thread Safety

Static members of this type are safe for multi-threaded operations. Instance members of this type are safe for multi-threaded operations.

Object Model








Supported Pixel Formats

Member NameDescription
Format1bppIndexed1 bit per pixel. Indexed.
Format4bppIndexed4 bits per pixel. Indexed.
Format8bppIndexed8 bits per pixel. Indexed.
Format8bppGrayScale8 bits per pixel. Grayscale. 8 bits are used for luminosity level.
Format16bppGrayScale16 bits per pixel. Grayscale. All 16 bits are used for luminosity level (extended pixel format).
Format16bppAGrayScale16 bits per pixel. Grayscale with alpha channel. 8 bits are used for alpha channel and other 8 bits are used for luminosity level.
Format32bppAGrayScale32 bits per pixel. Grayscale with alpha channel. 16 bits are used for alpha channel and other 16 bits are used for luminosity level (extended pixel format).
Format16bppRgb56516 bits per pixel. RGB. 5 bits each are used for the red, and blue components. 6 bits are used for green component.
Format16bppRgb55516 bits per pixel. RGB. 5 bits each are used for the red, green, and blue components. The rest bit is unused.
Format16bppArgb155516 bits per pixel. RGB with alpha channel. 1 bit is used for the alpha component, and 5 bits each are used for the red, green, and blue components.
Format24bppRgb24 bits per pixel. RGB. 8 bits each are used for the red, green, and blue components.
Format32bppRgb32 bits per pixel. RGB. 8 bits each are used for the red, green, and blue components. The rest 8 bits are unused.
Format32bppArgb32 bits per pixel. RGB with alpha channel. 8 bits each are used for the alpha, red, green, and blue components.
Format48bppRgb48 bits per pixel. RGB. 16 bits each are used for the red, green, and blue components (extended pixel format).
Format64bppArgb64 bits per pixel. RGB with alpha channel. 16 bits each are used for the alpha, red, green, and blue components (extended pixel format).
Format32bppCmyk32 bits per pixel. CMYK. 8 bits each are used for the cyan, magenta, yellow, and black components.
Format40bppAcmyk40 bits per pixel. CMYK with alpha channel. 8 bits each are used for the alpha, cyan, magenta, yellow, and black components.
Format64bppCmyk64 bits per pixel. CMYK. 16 bits each are used for the cyan, magenta, yellow, and black components (extended pixel format).
Format80bppAcmyk80 bits per pixel. CMYK with alpha channel. 16 bits each are used for the alpha, cyan, magenta, yellow, and black components (extended pixel format).

See Also

Reference