如何把一幅Gdiplus:Bit地图,把中间的一个矩形挖空?变成透明
怎么把一幅Gdiplus::Bitmap,把中间的一个矩形挖空?变成透明?
一幅Gdiplus::Bitmap,我想把中间的一个一个矩形区域,挖空,使得该矩形区域的所有像素值,都是RGBA(0, 0, 0, 0)。
有什么方法吗?
最好是效率高的方法。
------解决方案--------------------
Graphics::SetCompositingMode Method
--------------------------------------------------------------------------------
The SetCompositingMode method sets the compositing mode of this Graphics object.
Syntax
Status SetCompositingMode( CompositingMode compositingMode
);
Parameters
compositingMode
[in] Element of the CompositingMode enumeration that specifies the compositing mode.
Return Value
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.
Example
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 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.
Show Example
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);
}
Method Information
Stock Implementation gdiplus.dll
Header Declared in Gdiplusgraphics.h, include gdiplus.h
Import library gdiplus.lib
Minimum availability GDI+ 1.0
Minimum operating systems Windows 98/Me, Windows XP, Windows 2000, Windows NT 4.0 SP6
See Also
CompositingMode, GetCompositingMode, GetCompositingQuality, HatchBrush, SolidBrush, SetCompositingQuality, SetTextRenderingHint, TextRenderingHint, Alpha Blending Lines and Fills, New Features
--------------------------------------------------------------------------------
CompositingMode Enumerated Type
--------------------------------------------------------------------------------
The CompositingMode enumeration specifies how rendered colors are combined with background colors. This enumeration is used by the GetCompositingMode and SetCompositingMode methods of the Graphics class.
一幅Gdiplus::Bitmap,我想把中间的一个一个矩形区域,挖空,使得该矩形区域的所有像素值,都是RGBA(0, 0, 0, 0)。
有什么方法吗?
最好是效率高的方法。
------解决方案--------------------
Graphics::SetCompositingMode Method
--------------------------------------------------------------------------------
The SetCompositingMode method sets the compositing mode of this Graphics object.
Syntax
Status SetCompositingMode( CompositingMode compositingMode
);
Parameters
compositingMode
[in] Element of the CompositingMode enumeration that specifies the compositing mode.
Return Value
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.
Example
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 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.
Show Example
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);
}
Method Information
Stock Implementation gdiplus.dll
Header Declared in Gdiplusgraphics.h, include gdiplus.h
Import library gdiplus.lib
Minimum availability GDI+ 1.0
Minimum operating systems Windows 98/Me, Windows XP, Windows 2000, Windows NT 4.0 SP6
See Also
CompositingMode, GetCompositingMode, GetCompositingQuality, HatchBrush, SolidBrush, SetCompositingQuality, SetTextRenderingHint, TextRenderingHint, Alpha Blending Lines and Fills, New Features
--------------------------------------------------------------------------------
CompositingMode Enumerated Type
--------------------------------------------------------------------------------
The CompositingMode enumeration specifies how rendered colors are combined with background colors. This enumeration is used by the GetCompositingMode and SetCompositingMode methods of the Graphics class.