In this example:
Code File:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, comctrls, stdctrls, role; Type tform1 = Class (tform) Procedure formpaint (sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} uses gdipobj, gdipapi; Procedure tform1.formpaint (Sender: tobject); const colors: array [0 .. 3] of tgpcolor = (aclred, aclyellow, aclgreen, aclblue); pos: array [0 .. 3] of single = (0.0, 0.2, 0.6, 1.0); {it seems that the data at both ends must be 0 and 1} var G: tgpgraphics; Path: tgpgraphicspath; Pb: tgppathgradientbrush; num: integer; PTS: array of tgppoint; begin G: = tgpgraphics. create (canvas. handle); Path: = tgpgraphicspath. create; {create an elliptical path, draw a brush Based on the path, and then set the color using setinterpolationcolors} path. addellipse (makerect (10, 10, 150,150); Pb: = tgppathgradientbrush. create (PATH); Pb. setinterpolationcolors (@ colors, @ POs, length (POS); G. fillpath (Pb, PATH); {create a path painting brush Based on the elliptical path, and then set the color using setsurroundcolors} Pb. free; Pb: = tgppathgradientbrush. create (PATH); num: = length (POS); Pb. setsurroundcolors (@ colors, num); G. translatetransform (160, 0); G. fillpath (Pb, PATH); {create a path painter Based on the vertex array extracted from the elliptical path, and then set the color using setsurroundcolors} setlength (PTS, path. getpointcount); Path. getpathpoints (pgppoint (PTS), length (PTS); Pb. free; Pb: = tgppathgradientbrush. create (pgppoint (PTS), length (PTS); Pb. setcentercolor (aclwhite); {in this case, the center is black by default. I want white.} num: = length (colors); Pb. setsurroundcolors (@ colors, num); G. translatetransform (160, 0); G. fillpath (Pb, PATH); {create a path painter Based on the vertex array extracted from the elliptical path, and then set the color using setinterpolationcolors} // setlength (PTS, path. getpointcount); // path. getpathpoints (pgppoint (PTS), length (PTS); Pb. free; Pb: = tgppathgradientbrush. create (pgppoint (PTS), length (PTS); // Pb. setcentercolor (aclwhite); {center color is not required here} num: = length (colors); Pb. setinterpolationcolors (@ colors, @ POs, length (POS); G. translatetransform (160, 0); G. fillpath (Pb, PATH); Pb. free; Path. free; G. free; end.
Form file:
Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 169 clientwidth = 649 color = clbtnface font. charset = default_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] oldcreateorder = false position = pow.topcenter onpaint = formpaint pixelsperinch = 96 textheight = 13end