Graphics::GetCompositingMode method (gdiplusgraphics.h)

The Graphics::GetCompositingMode method gets the compositing mode currently set for this Graphics object.

Syntax

CompositingMode GetCompositingMode();

Return value

Type: CompositingMode

This method returns an element of the CompositingMode enumeration that indicates the compositing mode currently set for this Graphics object.

Remarks

Suppose you create a SolidBrush object based on a color that has an alpha component of 192, which is about 75 percent of 255. If your Graphics object has its compositing mode set to CompositingModeSourceOver, then areas filled with the solid brush are a blend that is 75 percent brush color and 25 percent background color. If your Graphics object has its compositing mode set to CompositingModeSourceCopy, then the background color is not blended with the brush color. However, the color rendered by the brush has an intensity that is 75 percent of what it would be if the alpha component were 255.

Examples

The following example creates a Graphics object and sets its compositing mode to CompositingModeSourceCopy. The code creates a SolidBrush object based on a color with an alpha component of 128. The code passes the address of that brush to the Graphics::FillRectangle method of the Graphics object to fill a rectangle with a color that is not blended with the background color. The call to the Graphics::GetCompositingMode method of the Graphics object demonstrates how to obtain the compositing mode (which is already known in this case). The code determines whether the compositing mode is CompositingModeSourceCopy and if so, changes it to CompositingModeSourceOver. Then the code calls Graphics::FillRectangle a second time to fill a rectangle with a color that is a half-and-half blend of the brush color and the background color.

VOID Example_GetCompositingMode(HDC hdc)
{
   Graphics graphics(hdc);
   
   graphics.SetCompositingMode(CompositingModeSourceCopy);
   SolidBrush alphaBrush(Color(128, 255, 0, 0));
   graphics.FillRectangle(&alphaBrush, 0, 0, 100, 100);
   
   // Get the compositing mode.
   CompositingMode compMode = graphics.GetCompositingMode();
   
   // Change the compositing mode if it is CompositingModeSourceCopy.
   if(compMode == CompositingModeSourceCopy)
   {
      graphics.SetCompositingMode(CompositingModeSourceOver);
   }  
  
   graphics.FillRectangle(&alphaBrush, 0, 100, 100, 100);
}

Requirements

Requirement Value
Minimum supported client Windows XP, Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header gdiplusgraphics.h (include Gdiplus.h)
Library Gdiplus.lib
DLL Gdiplus.dll

See also

Alpha Blending Lines and Fills

Graphics

Graphics::GetCompositingQuality

Graphics::SetCompositingMode

Graphics::SetCompositingQuality

HatchBrush

New Features

SolidBrush

Using Compositing Mode to Control Alpha Blending