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)
Public NotInheritable Class PixelFormatConverter _ Inherits BitmapTransform
public sealed class PixelFormatConverter : BitmapTransform
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. |
Member Name | Description |
---|---|
Format1bppIndexed | 1 bit per pixel. Indexed. |
Format4bppIndexed | 4 bits per pixel. Indexed. |
Format8bppIndexed | 8 bits per pixel. Indexed. |
Format8bppGrayScale | 8 bits per pixel. Grayscale. 8 bits are used for luminosity level. |
Format16bppGrayScale | 16 bits per pixel. Grayscale. All 16 bits are used for luminosity level (extended pixel format). |
Format16bppAGrayScale | 16 bits per pixel. Grayscale with alpha channel. 8 bits are used for alpha channel and other 8 bits are used for luminosity level. |
Format32bppAGrayScale | 32 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). |
Format16bppRgb565 | 16 bits per pixel. RGB. 5 bits each are used for the red, and blue components. 6 bits are used for green component. |
Format16bppRgb555 | 16 bits per pixel. RGB. 5 bits each are used for the red, green, and blue components. The rest bit is unused. |
Format16bppArgb1555 | 16 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. |
Format24bppRgb | 24 bits per pixel. RGB. 8 bits each are used for the red, green, and blue components. |
Format32bppRgb | 32 bits per pixel. RGB. 8 bits each are used for the red, green, and blue components. The rest 8 bits are unused. |
Format32bppArgb | 32 bits per pixel. RGB with alpha channel. 8 bits each are used for the alpha, red, green, and blue components. |
Format48bppRgb | 48 bits per pixel. RGB. 16 bits each are used for the red, green, and blue components (extended pixel format). |
Format64bppArgb | 64 bits per pixel. RGB with alpha channel. 16 bits each are used for the alpha, red, green, and blue components (extended pixel format). |
Format32bppCmyk | 32 bits per pixel. CMYK. 8 bits each are used for the cyan, magenta, yellow, and black components. |
Format40bppAcmyk | 40 bits per pixel. CMYK with alpha channel. 8 bits each are used for the alpha, cyan, magenta, yellow, and black components. |
Format64bppCmyk | 64 bits per pixel. CMYK. 16 bits each are used for the cyan, magenta, yellow, and black components (extended pixel format). |
Format80bppAcmyk | 80 bits per pixel. CMYK with alpha channel. 16 bits each are used for the alpha, cyan, magenta, yellow, and black components (extended pixel format). |