GdipCreatePathGradientFromPathfunction
Creates a **PathGradientBrush** object based on a **GraphicsPath** object.
Syntax
FUNCTION GdipCreatePathGradientFromPath (BYVAL path AS CONST GpPath PTR, BYVAL polyGradient AS GpPathGradient PTR PTR) AS GpStatus
Parameters
| Name | Description | |
|---|---|---|
path | [in] Pointer to a GraphicsPath object that specifies the boundary path of the path gradient brush. | |
polyGradient | [out] Pointer to a variable that receives a pointer to the new PathGradientBrush object. |
Description
Creates a PathGradientBrush object based on a GraphicsPath object.
Example
' ======================================================================================== ' The following example draws a star-shaped GraphicsPath. ' Creates a star-shaped GraphicsPath and fills it using a PathGradientBrush constructed ' from that path. The gradient transitions from a red center to a set of surround colors ' defined at each vertex of the star. DPI scaling is applied globally to ensure consistent ' rendering across high-resolution displays. ' ======================================================================================== SUB Example_CreatePathGradientFromPath (BYVAL hdc AS HDC)
DIM hStatus AS LONG
' // Create a graphics object from the device context DIM graphics AS GpGraphics PTR hStatus = GdipCreateFromHDC(hdc, @graphics)
' // Get the DPI scaling ratios DIM dpiX AS SINGLE hStatus = GdipGetDpiX(graphics, @dpiX) DIM rxRatio AS SINGLE = dpiX / 96 DIM dpiY AS SINGLE hStatus = GdipGetDpiY(graphics, @dpiY) Dim ryRatio AS SINGLE = dpiY / 96 ' // Set the scale transform hStatus = GdipScaleWorldTransform(graphics, rxRatio, ryRatio, MatrixOrderPrepend)
' // Create a GraphicsPath object and initializes the fill mode. DIM path AS GpPath PTR hStatus = GdipCreatePath(FillModeAlternate, @path)
' // Fill the array of points. DIM pts(0 TO 9) AS GpPointF pts(0).x = 75 : pts(0).y = 0 pts(1).x = 100 : pts(1).y = 50 pts(2).x = 150 : pts(2).y = 50 pts(3).x = 112 : pts(3).y = 75 pts(4).x = 150 : pts(4).y = 150 pts(5).x = 75 : pts(5).y = 100 pts(6).x = 0 : pts(6).y = 150 pts(7).x = 37 : pts(7).y = 75 pts(8).x = 0 : pts(8).y = 50 pts(9).x = 50 : pts(9).y = 50
' // Construct the path with the array of points. hStatus = GdipAddPathLine2(path, @pts(0), 10)
' // Use the path to construct a path gradient brush. DIM brush AS GpPathGradient PTR hStatus = GdipCreatePathGradientFromPath(path, @brush)
' // Set the color at the center of the path to red. hStatus = GdipSetPathGradientCenterColor(brush, ARGB_RED)
' // Set the colors of the points in the array. DIM Colors(9) AS ARGB Colors(0) = ARGB_BLACK Colors(1) = ARGB_LIGHTGREEN Colors(2) = ARGB_BLUE Colors(3) = ARGB_WHITE Colors(4) = ARGB_BLACK Colors(5) = ARGB_LIGHTGREEN Colors(6) = ARGB_BLUE Colors(7) = ARGB_WHITE Colors(8) = ARGB_BLACK Colors(9) = ARGB_LIGHTGREEN DIM count AS LONG = 10 hStatus = GdipSetPathGradientSurroundColorsWithCount(brush, @Colors(0), @count)
' // Fill the path with the path gradient brush. hStatus = GdipFillPath(graphics, brush, path)
' // Cleanup IF path THEN GdipDeletePath(path) IF brush THEN GdipDeleteBrush(brush) IF graphics THEN GdipDeleteGraphics(graphics)
END SUB ' ========================================================================================
Reference
- Defined in AfxNova/AfxGdiPlus.bi:2238
- Documented in Graphics/GdiPlus Flat Api/GdiPlusPathGradientBrush.md
- Topic: GdiPlusPathGradientBrush