Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

Graphics.SetCompositingMode method

Applies to: desktop apps only

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

Syntax

Status SetCompositingMode(
  [in]  CompositingMode compositingMode
);

Parameters

compositingMode [in]

Type: CompositingMode

Element of the CompositingMode enumeration that specifies the compositing mode.

Return value

Type:

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

Minimum supported client

Windows XP, Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Product

GDI+ 1.0

Header

Gdiplusgraphics.h (include Gdiplus.h)

Library

Gdiplus.lib

DLL

Gdiplus.dll

See also

Graphics
CompositingMode
Graphics::GetCompositingMode
Graphics::GetCompositingQuality
HatchBrush
SolidBrush
Graphics::SetCompositingQuality
Graphics::SetTextRenderingHint
TextRenderingHint
Alpha Blending Lines and Fills
New Features

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Community Additions

ADD
Show:
© 2015 Microsoft