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:
- 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. - Use the CreateColorTransform function to create a color transform (HTRANSFORM) between the two color spaces.
- 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.
- Use the TranslateBitmapBits function to translate the image bits.
- 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