Microsoft KB Archive/317825

= HOW TO: Use GDI+ and Image Color Management to Adjust Image Colors =

Article ID: 317825

Article Last Modified on 4/21/2006

-

APPLIES TO


 * Microsoft .NET Framework Software Development Kit 1.0 Service Pack 2
 * Microsoft GDI+ 1.0
 * Microsoft Platform Software Development Kit-January 2000 Edition
 * Microsoft Windows XP Professional
 * Microsoft Windows XP Professional for Itanium-based systems

-



This article was previously published under Q317825



IN THIS TASK
SUMMARY
 * Use the ColorMatrix Class for Linear Color Transformations
 * Use ICM for Non-Linear Color Transformations

REFERENCES



SUMMARY
When you use the Microsoft .NET Framework to write a graphics program, you may want to do image color transformations. This article describes two different ways to adjust image color.

NOTE: The System.Drawing namespace provides access to the GDI+ application programming interface (API). The remainder of this article uses the term GDI+.

back to the top

Use the ColorMatrix Class for Linear Color Transformations
You can use the ColorMatrix class to transform image colors. To do this, you specify color adjustment matrices through certain methods of the ImageAttributes class (for example, the SetColorMatrix method).

However, because the ColorMatrix class only provides coordinates for the red, green, blue, alpha (RGBA) color space, you are limited to linear transformations. Linear transformations are transformations from one RGBA color space to another RGBA color space.

Therefore, GDI+ does not natively provide the same level of color transformation functionality that Microsoft Image Color Management (ICM) does.

back to the top

Use ICM for Non-Linear Color Transformations
Image Color Management version 2.0 is a standard system component of Microsoft Windows 98, Microsoft Windows 2000, and Microsoft Windows XP. ICM is built into these operating systems as a subset of the Win32 application programming interface (API) and is available in any Win32 application.

If you want to do non-linear color transformations from a GDI+ based application, for example from red-green-blue (RGB) to hue, saturation, and value (HSV), you must interoperate with the Win32 API (specifically, the GDI and ICM API sets).

For additional information about how to interoperate between GDI+ and GDI, click the article number below to view the article in the Microsoft Knowledge Base:

311221 INFO: Interoperability Between GDI and GDI+

Specifically, see the &quot;Using GDI+ on a GDI Memory HBITMAP&quot; section of 311221, in which the GDI Memory HBITMAP is the image that ICM manipulates.

Although a detailed description of how to transform image colors with the ICM API is beyond the scope of this article, the following general steps demonstrate one way to tie the ICM code with the target image:
 * 1) Define the source and the destination color spaces for the transformation. This requires an International Color Consortium (ICC) color profile for the destination color space and an ICC color profile or logical color space (LCS) for the source color space.

For more information about color profiles, see the &quot;References&quot; section.
 * 1) Use the CreateColorTransform function to create a color transform (HTRANSFORM) between the two color spaces.
 * 2) Load the image as a DIBSection for easy access to the image bits. Note that you can load and initialize the DIBSection image through GDI+ only if you follow the steps to interoperate in 311221.
 * 3) Use the TranslateBitmapBits function to translate the image bits.
 * 4) If you want to, you can interoperate back to GDI+ with the newly transformed image.

back to the top

