Graphics::SetCompositingMode method (gdiplusgraphics.h)

The Graphics::SetCompositingMode method sets the compositing mode of this Graphics object.

Syntax

Status SetCompositingMode(
  [in] CompositingMode compositingMode
);

Parameters

[in] compositingMode

Type: CompositingMode

Element of the CompositingMode enumeration that specifies the compositing mode.

Return value

Type: Status

If the method succeeds, it returns Ok, which is an element of the Status enumeration.

If the method fails, it returns one of the other elements of the Status enumeration.

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.

You cannot use CompositingModeSourceCopy along with TextRenderingHintClearTypeGridFit.

Examples

The following example creates a Graphics object and sets its compositing mode to CompositingModeSourceOver. The code creates a SolidBrush object based on a color that has 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 a half-and-half blend of the brush color and the background color. Then the code sets the compositing mode of the Graphics object to CompositingModeSourceCopy and fills a second rectangle with the same brush. In that second rectangle, the brush color is not blended with the background color.

VOID Example_SetCompositingMode(HDC hdc)
{
   Graphics graphics(hdc);
   
   // Create a SolidBrush object with an alpha-blended color.
   SolidBrush alphaBrush(Color(180, 255, 0, 0));

   // Set the compositing mode to CompositingModeSourceOver,
   // and fill a rectangle.
   graphics.SetCompositingMode(CompositingModeSourceOver);
   graphics.FillRectangle(&alphaBrush, 0, 0, 100, 100);

   // Set the compositing mode to CompositingModeSourceCopy,
   // and fill a rectangle.
   graphics.SetCompositingMode(CompositingModeSourceCopy);
   graphics.FillRectangle(&alphaBrush, 100, 0, 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

CompositingMode

Graphics

Graphics::GetCompositingMode

Graphics::GetCompositingQuality

Graphics::SetCompositingQuality

Graphics::SetTextRenderingHint

HatchBrush

New Features

SolidBrush

TextRenderingHint