HOW TO: Use GDI+ and Image Color Management to Adjust Image Colors (317825)



The information in this article applies to:

  • Microsoft .NET Framework SDK 1.0
  • Microsoft GDI+ 1.0
  • Microsoft Platform Software Development Kit (SDK) 1.0
  • Microsoft Windows XP Professional
  • the operating system: Microsoft Windows XP 64-Bit Edition

This article was previously published under Q317825

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 "Using GDI+ on a GDI Memory HBITMAP" 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 "References" section.
  2. Use the CreateColorTransform function to create a color transform (HTRANSFORM) between the two color spaces.
  3. 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.
  4. Use the TranslateBitmapBits function to translate the image bits.
  5. If you want to, you can interoperate back to GDI+ with the newly transformed image.
back to the top

REFERENCES

For more information about Image Color Management 2.0, see following Platform Software Development Kit (SDK) documentation at the following MSDN Web site: For more information about ICC color profiles, see the following International Color Consortium Web site: Microsoft provides third-party contact information to help you find technical support. This contact information may change without notice. Microsoft does not guarantee the accuracy of this third-party contact information.

back to the top

Modification Type:MajorLast Reviewed:4/21/2006
Keywords:kbDSWGDI2003Swept kbColor kbHOWTOmaster KB317825 kbAudDeveloper