• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipGetLineColors

Started by José Roca, June 22, 2008, 02:28:09 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates a linear gradient brush and gets the boundary colors. Next, the code uses each of the two colors to create a solid brush. Then, the code fills a rectangle with each solid brush.

C++


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

   // Create a linear gradient brush.
   LinearGradientBrush linGrBrush(
      Rect(0, 0, 100, 50),
      Color(255, 0, 0, 0),    // black
      Color(255, 0, 0, 255),  // blue
      LinearGradientModeHorizontal);

   // Obtain information about the linear gradient brush.
   Color colors[2];
   linGrBrush.GetLinearColors(colors);

   // Fill a small rectangle with each of the two colors.
   SolidBrush solidBrush0(colors[0]);
   SolidBrush solidBrush1(colors[1]);
   myGraphics.FillRectangle(&solidBrush0, 0, 0, 20, 20);
   myGraphics.FillRectangle(&solidBrush1, 25, 0, 20, 20);
}


PowerBASIC


SUB GDIP_GetLineColors (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pLinBrush AS DWORD
   LOCAL colorBlack AS DWORD
   LOCAL colorBlue AS DWORD
   LOCAL pSolidBrush0 AS DWORD
   LOCAL pSolidBrush1 AS DWORD
   LOCAL pt1 AS POINTF
   LOCAL pt2 AS POINTF
   DIM   colors(1) AS DWORD

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Create a linear gradient brush.
   pt1.x = 0 : pt1.y = 0 : pt2.x = 100 : pt2.y = 50
   colorBlack = GDIP_ARGB(255, 0, 0, 0)
   colorBlue = GDIP_ARGB(255, 0, 0, 255)
   hStatus = GdipCreateLineBrush(pt1, pt2, colorBlack, colorBlue, %WrapModeTile, pLinBrush)

   ' // Obtain information about the linear gradient brush.
   hStatus = GdipGetLineColors(pLinBrush, colors(0))

   ' // Fill a small rectangle with each of the two colors.
   hStatus = GdipCreateSolidFill(colors(0), pSolidBrush0)
   hStatus = GdipCreateSolidFill(colors(1), pSolidBrush1)

   hStatus = GdipFillRectangle(pGraphics, pSolidBrush0, 0, 0, 20, 20)
   hStatus = GdipFillRectangle(pGraphics, pSolidBrush1, 25, 0, 20, 20)

   ' // Cleanup
   IF pSolidBrush0 THEN hStatus = GdipDeleteBrush(pSolidBrush0)
   IF pSolidBrush1 THEN hStatus = GdipDeleteBrush(pSolidBrush1)
   IF pLinBrush THEN GdipDeleteBrush(pLinBrush)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB