The bitmap transform classes
Written by Administrator   
Monday, 22 March 2010
Article Index
The bitmap transform classes
Transformations
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.

Banner

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.BeginInit();
fcb.Source = bmi;
fcb.DestinationFormat =
PixelFormats.Gray32Float;
fcb.EndInit();
image1.Source = fcb;

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

grey

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

C:\Windows\System32\spool\drivers\color

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:

C:\Windows\System32\spool\drivers\
colorzee139_1.icm

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

ColorConvertedBitmap ccb = 
new ColorConvertedBitmap();
ccb.BeginInit();
ccb.Source = bmi;
ccb.SourceColorContext =
new ColorContext(bmi.Format);
ccb.DestinationColorContext =
new ColorContext(
new Uri(@"C:\Windows\System32\
spool\drivers\color\
EE139__1.ICM",
UriKind.Absolute));
ccb.DestinationFormat=bmi.Format;
ccb.EndInit();

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.

colorspace

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.

Banner


FlexGrid - A Lightweight Data Grid

There are more data grids available than the standard one that comes with WPF. In this article we take a look at FlexGrid for WPF and discover how easy it is to use.



Loading Bitmaps: DoEvents and the closure pattern

Sometimes loading a bitmap causes an asynchronous download and you have to wait for it to complete before using it - but how best to wait? The standard solution is to use an event but this breaks what [ ... ]



Getting Started with WPF

 

WPF Windows Presentation Foundation is the new way to do forms and all things graphical in .NET. You can still use  Windows Forms but don't expect anything particularly new to be added to [ ... ]



Bitmap Effects

WPF bitmap effects are easy to use but subtle. Before moving on to consider custom effects we take a careful look at what is provided as standard.



Custom BitmapSource

Even if you don't anticipate implementing your own custom BitmapSource finding out how to reveals quite a lot about the way that WPF bitmaps work.


Other Articles

<ASIN:2888930188>

<ASIN:B000244BZO>

<ASIN:0321267222>

<ASIN:1933952024>

<ASIN:0470058250>

<ASIN:3540671196>



Last Updated ( Monday, 22 March 2010 )