The bitmap transform classes
The bitmap transform classes
Monday, 22 March 2010
Article Index
The bitmap transform classes
Format and color conversion


Pixel format conversion

The FormatConvertedBitmap class does what you might expect - it coverts the pixel format of one bitmap to a specified format.


Notice however that it is much simpler than the ColorConvertedBitmap class which performs a colour conversion taking account of color profiles rather than a format conversion.

The class works in the same way as the other transformation classes. All you have to do is set the Source property to the input bitmap and the DestinationPixel property for the output bitmap. For example:

FormatConvertedBitmap fcb = 
new FormatConvertedBitmap();
fcb.Source = bmi;
fcb.DestinationFormat =
image1.Source = fcb;

This converts the pixel format to gray32 and the result is a grey scale image.


Original and pixel format converted to grey scale

Notice you can't modify the way colors are mapped to grey.

Color space conversion

The ColorConvertedBitmap class takes an object derived from BitmapSource and changes the way that color is represented at each pixel.

It isn't really about changing the pixelformat but about remapping the range of colors used - it really is about changing the color space.

For example, if you have a color bitmap obtained from a scanner that you have a color profile for you can convert its color space so that it displays correctly on an output device that you have a color profile for.

The class already knows about the standard color spaces and can use custom ICC or ICM color profiles.

Windows maintains a set of color profiles for system devices and you can view these using the Color Management tool in the Control Panel.

Profiles can also be downloaded for many printers and display devices - visit the manufacturer's website - and many are installed when you install the device drivers.

You can find most of the color profiles installed in your system in


The ultimate in color management is having a custom profile prepared for a display or a printer by a specialist company using a spectrophotometer.

The ColorConvertedBitmap  works in much the same way as the other transformation classes.  You simply set the Source property to the bitmap you need to convert and the DestinationFormat which specifies the pixel format of the output bitmap - this can be the same as the input bitmap. In addition you have to specify the color profile of the source and destination bitmap in the SourceColorContext and the DestinationColorContext respectively.

You can specify default color profiles for the pixel formats in use simply by using the pixel formats in the ColorContext constructor. However, in most cases if you are interested in color space conversion you need to make use of profiles. It is also worth noting that some bitmap formats store their ColorContext as part of the file.

For example, suppose that there is a profile for an Epson inkjet printer stored in:


then we can convert a bitmap to this printer's color space using something like:

ColorConvertedBitmap ccb = 
new ColorConvertedBitmap();
ccb.Source = bmi;
ccb.SourceColorContext =
new ColorContext(bmi.Format);
ccb.DestinationColorContext =
new ColorContext(
new Uri(@"C:\Windows\System32\

The SourceColorContext is set to the default for its pixel format but the DestinationColorContext is set to the profile stored on disk. Notice that the pixel formats are not changed by the conversion.

If you display the result using an Image control on a standard display then the result will look  different from the original - but how different depends on the profile and the display device.


Original with default color profile and a printer profile

Color profiling and control is a big subject but essentially if you have color profiles for every display, input device and printer and make use of them when ever you get a bitmap ready for rendering to the device everything should look as good as it possibly can given the limitations of the devices.


Bitmap Coding and Metatdata in WPF

Having looked at working with raw pixel data we turn our attention to formattted image files and how to code and decode both the pixel data and the meta data they contain.


ISupportInitialize and XAML

For a class to be instantiated by XAML it has to have a parameter-less constructor. This means that properties that might be essential to creating the instance can be initialized in any order and this [ ... ]

RenderTargetBitmap - Visual vector to bitmap

RenderTargetBitmap will convert any Visual to a bitmap but sometimes it isn't quite as straighforward as just calling Render().

Routed Events

Routed events were new in .NET 3.5 but there is still plenty to discover about using them. We look at bubbling and tunneling and how to create your own routed even and how WPF changes the underlying m [ ... ]

Custom Bitmap Effects - Getting started

The simplest possible custom effects project is enough for you to see how it all works and to move on to building your own effects that do something useful. This is an introduction to using HLSL in WP [ ... ]

Other Articles







Last Updated ( Monday, 22 March 2010 )

RSS feed of all content
I Programmer - full contents
Copyright © 2018 All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.