• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipAddPathLine2I

Started by José Roca, June 23, 2008, 05:17:49 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example draws a star-shaped GraphicsPath.


SUB GDIP_AddPathLine2 (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pBrush AS DWORD
   LOCAL pPath AS DWORD
   DIM   pt(9) AS POINTL
   DIM   Colors(9) AS DWORD

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' Create a GraphicsPath.
   hStatus = GdipCreatePath(%FillModeAlternate, pPath)

   ' // Fill the array of points.
   pt(0).x = 75  : pt(0).y = 0
   pt(1).x = 100 : pt(1).y = 50
   pt(2).x = 150 : pt(2).y = 50
   pt(3).x = 112 : pt(3).y = 75
   pt(4).x = 150 : pt(4).y = 150
   pt(5).x = 75  : pt(5).y = 100
   pt(6).x = 0   : pt(6).y = 150
   pt(7).x = 37  : pt(7).y = 75
   pt(8).x = 0   : pt(8).y = 50
   pt(9).x = 50  : pt(9).y = 50

   ' Construct the path with the array of points.
   hStatus = GdipAddPathLine2I(pPath, pt(0), 10)

   ' // Use the path to construct a path gradient brush.
   hStatus = GdipCreatePathGradientFromPath(pPath, pBrush)

   ' // Set the color at the center of the path to red.
   hStatus = GdipSetPathGradientCenterColor(pBrush, GDIP_ARGB(255, 255, 0, 0))

   ' // Set the colors of the points in the array.
   Colors(0) = GDIP_ARGB(255, 0, 0, 0)
   Colors(1) = GDIP_ARGB(255, 0, 255, 0)
   Colors(2) = GDIP_ARGB(255, 0, 0, 255)
   Colors(3) = GDIP_ARGB(255, 255, 255, 255)
   Colors(4) = GDIP_ARGB(255, 0, 0, 0)
   Colors(5) = GDIP_ARGB(255, 0, 255, 0)
   Colors(6) = GDIP_ARGB(255, 0, 0, 255)
   Colors(7) = GDIP_ARGB(255, 255, 255, 255)
   Colors(8) = GDIP_ARGB(255, 0, 0, 0)
   Colors(9) = GDIP_ARGB(255, 0, 255, 0)

   hStatus = GdipSetPathGradientSurroundColorsWithCount(pBrush, Colors(0), 9)

   ' // Fill the path with the path gradient brush.
   hStatus = GdipFillPath(pGraphics, pBrush, pPath)

   ' // Cleanup
   IF pPath THEN GdipDeletePath(pPath)
   if pBrush THEN GdipDeleteBrush(pBrush)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB