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


Drawing Bitmaps – DrawingImage and DrawingVisual

 

WPF provides multiple ways to convert vector drawings to bitmaps. Find out how DrawingImage and DrawingVisual work and when to use which. On the way we look at how to create 2D vector drawings.



Custom Bitmap Effects - HLSL

In the article Custom Bitmap Effects - Getting started we discovered how to work with HLSL in WPF. Now we are in a position to write more sophisticated shaders and  this means learning some more  [ ... ]



WPF .NET Core - Creating Objects With XAML

If you've never encountered WPF (Windows Presentation Foundation) you are missing a versatile tool. This article is part of a series devoted to it. XAML can be confusing - especially if you think it i [ ... ]



Comparative Analysis of Browser Protection Software and Coding Practices

The digital space is awash with an array of threats, from hackers to malware and viruses, making browser protection software and secure coding practices crucial to safeguarding data. As tech [ ... ]



BitmapSource: WPF Bitmaps

Although bitmap graphics are not a main focus of WPF it does offer some useful facilities


Other Articles

<ASIN:2888930188>

<ASIN:B000244BZO>

<ASIN:0321267222>

<ASIN:1933952024>

<ASIN:0470058250>

<ASIN:3540671196>



Last Updated ( Monday, 22 March 2010 )