• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipSetLineLinearBlend

Started by José Roca, June 22, 2008, 01:33:39 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 triangular-shaped blend, and uses the brush to fill a rectangle. Twice more, the code sets a triangular-shaped blend with different values and, each time, uses the brush to fill a rectangle.

C++


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

   LinearGradientBrush linGrBrush(
      Point(0, 0),
      Point(500, 0),
      Color(255, 255, 0, 0),   // red
      Color(255, 0, 0, 255));  // blue

   linGrBrush.SetBlendTriangularShape(0.5f, 0.6f);
   myGraphics.FillRectangle(&linGrBrush, 0, 0, 500, 50);

   linGrBrush.SetBlendTriangularShape(0.5f, 0.8f);
   myGraphics.FillRectangle(&linGrBrush, 0, 75, 500, 50);

   linGrBrush.SetBlendTriangularShape(0.5f, 1.0f);
   myGraphics.FillRectangle(&linGrBrush, 0, 150, 500, 50);
}


PowerBASIC


SUB GDIP_SetLineLinearBlend (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pt1 AS POINTF
   LOCAL pt2 AS POINTF
   LOCAL colorRed AS DWORD
   LOCAL colorBlue AS DWORD
   LOCAL pLinBrush AS DWORD

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   pt1.x = 0 : pt1.y = 0 : pt2.x = 500 : 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 = GdipSetLineLinearBlend(pLinBrush, 0.5, 0.6)
   hStatus = GdipFillRectangle(pGraphics, pLinBrush, 0, 0, 500, 50)

   hStatus = GdipSetLineLinearBlend(pLinBrush, 0.5, 0.8)
   hStatus = GdipFillRectangle(pGraphics, pLinBrush, 0, 75, 500, 50)

   hStatus = GdipSetLineLinearBlend(pLinBrush, 0.5, 1.0)
   hStatus = GdipFillRectangle(pGraphics, pLinBrush, 0, 150, 500, 50)

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

END SUB