The following example creates a linear gradient brush, sets its blend, and uses the brush to fill a rectangle. The code then gets the blend. The blend factors and positions can then be inspected or used in some way.
C++
VOID Example_GetBlend(HDC hdc)
{
Graphics myGraphics(hdc);
// Create a linear gradient brush, and set its blend.
REAL fac[] = {0.0f, 0.4f, 0.6f, 1.0f};
REAL pos[] = {0.0f, 0.2f, 0.8f, 1.0f};
LinearGradientBrush linGrBrush(
Point(0, 0),
Point(100, 0),
Color(255, 255, 0, 0), // red
Color(255, 0, 0, 255)); // blue
linGrBrush.SetBlend(fac, pos, 4);
// Use the linear gradient brush to fill a rectangle.
myGraphics.FillRectangle(&linGrBrush, 0, 0, 100, 50);
// Obtain information about the linear gradient brush.
INT blendCount;
REAL* factors = NULL;
REAL* positions = NULL;
blendCount = linGrBrush.GetBlendCount();
factors = new REAL[blendCount];
positions = new REAL[blendCount];
linGrBrush.GetBlend(factors, positions, blendCount);
for(INT j = 0; j < blendCount; ++j)
{
// Inspect or use the value in factors[j].
// Inspect or use the value in positions[j].
}
}
PowerBASIC
SUB GDIP_GetLineBlend (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pLinBrush AS DWORD
LOCAL colorRed AS DWORD
LOCAL colorBlue AS DWORD
LOCAL blendCount AS LONG
LOCAL pt1 AS POINTF
LOCAL pt2 AS POINTF
LOCAL i AS LONG
DIM fac(3) AS SINGLE
DIM pos(3) AS SINGLE
DIM factors(0) AS SINGLE
DIM positions(0) AS SINGLE
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Create a linear gradient brush, and set its blend.
fac(0) = 0.0! : fac(1) = 0.4! : fac(2) = 0.6! : fac(3) = 1.0!
pos(0) = 0.0! : pos(1) = 0.2! : pos(2) = 0.8! : pos(3) = 1.0!
pt1.x = 0 : pt1.y = 0 : pt2.x = 100 : pt2.y = 0
colorRed = GDIP_ARGB(255, 255, 0, 0)
colorBlue = GDIP_ARGB(255, 0, 0, 255)
hStatus = GdipCreateLineBrush(pt1, pt2, colorRed, colorBlue, %WrapModeTile, pLinBrush)
hStatus = GdipSetLineBlend(pLinBrush, fac(0), pos(0), 4)
' // Use the linear gradient brush to fill a rectangle.
hStatus = GdipFillRectangle(pGraphics, pLinBrush, 0, 0, 100, 50)
' // Obtain information about the linear gradient brush.
hStatus = GdipGetLineBlendCount(pLinBrush, blendCount)
IF blendCount THEN
REDIM factors(blendCount-1)
REDIM positions(blendCount-1)
hStatus = GdipGetLineBlend(pLinBrush, factors(0), positions(0), blendCount)
FOR i = 0 TO blendCount
OutputDebugString "factor " & FORMAT$(i) & " =" & STR$(factors(i))
OutputDebugString "position " & FORMAT$(i) & " =" & STR$(positions(i))
NEXT
END IF
' // Cleanup
IF pLinBrush THEN GdipDeleteBrush(pLinBrush)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipGetLineBlend.png)