• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipSetLineBlend

Started by José Roca, June 22, 2008, 01:26:33 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates a linear gradient brush, sets a custom blend, and uses the brush to fill a rectangle.

C++


VOID Example_SetBlend(HDC hdc)
{
   Graphics myGraphics(hdc);

   REAL factors[4] = {0.0f, 0.4f, 0.6f, 1.0f};
   REAL positions[4] = {0.0f, 0.2f, 0.8f, 1.0f};
   Rect rect(0, 0, 100, 50);

   LinearGradientBrush linGrBrush(
      rect,
      Color(255, 255, 0, 0),  // red
      Color(255, 0, 0, 255),  // blue
      LinearGradientModeHorizontal);

   linGrBrush.SetBlend(factors, positions, 4);
   myGraphics.FillRectangle(&linGrBrush, rect);
}


PowerBASIC


SUB GDIP_SetLineBlend (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL rc AS RECTF
   LOCAL colorRed AS DWORD
   LOCAL colorBlue AS DWORD
   LOCAL pLinBrush AS DWORD
   DIM   factors(3) AS SINGLE
   DIM   positions(3) AS SINGLE

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   rc.x = 0 : rc.y = 0 : rc.Width = 100 : rc.Height = 50
   colorRed = GDIP_ARGB(255, 255, 0, 0)
   colorBlue = GDIP_ARGB(255, 0, 0, 255)
   factors(0) = 0.0! : factors(1) = 0.4! : factors(2) = 0.6! : factors(3) = 1.0!
   positions(0) = 0.0! : positions(1) = 0.2! : positions(2) = 0.8! : positions(3) = 1.0!

   hStatus = GdipCreateLineBrushFromRect(rc, colorRed, colorBlue, %LinearGradientModeHorizontal, %WrapModeTile, pLinBrush)
   hStatus = GdipSetLineBlend(pLinBrush, factors(0), positions(0), 4)
   hStatus = GdipFillRectangle(pGraphics, pLinBrush, rc.x, rc.y, rc.Width, rc.Height)

   ' // Cleanup
   IF pLinBrush THEN GdipDeleteBrush(pLinBrush)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB