Method 2: tgplineargradientbrush. Create (rectangle, color 1, color 2, gradient mode );
Third Construction Method: tgplineargradientbrush. Create (rectangle, color 1, color 2, angle );
In the third construction method, the "angle" (X axis, clockwise) is equivalent to the custom gradient mode. The following two testsCodeThe results are the same.
In addition, the third construction method also has a Boolean parameter with the default value of false, indicating whether the specified angle is affected by other transformations.
Test:
Test 1:
Uses gdiplus; Procedure injection (Sender: tobject); const C1 = $ ffff0000; C2 = $ ff0000ff; var graphics: igpgraphics; rect, rectbrush: tgprect; brush: cursor; begin graphics: = tgpgraphics. create (canvas. handle); rect. initialize (10, 10,200,150); rectbrush. initialize (rect. X + rect. width Div 8, rect. Y + rect. height Div 8, rect. width Div 4, rect. height Div 4); // lineargradientmodehorizontal is the default value of the brush: = tgplineargradientbrush. create (rectbrush, C1, C2, lineargradientmodehorizontal); graphics. fillrectangle (brush, rect); graphics. translatetransform (0, rect. height + rect. y); brush: = tgplineargradientbrush. create (rectbrush, C1, C2, lineargradientmodevertical); graphics. fillrectangle (brush, rect); graphics. translatetransform (rect. width + rect. x,-graphics. transform. offsety); brush: = tgplineargradientbrush. create (rectbrush, C1, C2, lineargradientmodeforwarddiagonal); graphics. fillrectangle (brush, rect); graphics. translatetransform (0, rect. height + rect. y); brush: = tgplineargradientbrush. create (rectbrush, C1, C2, lineargradientmodebackwarddiagonal); graphics. fillrectangle (brush, rect); end;
Test 2:
Uses gdiplus; Procedure injection (Sender: tobject); const C1 = $ ffff0000; C2 = $ ff0000ff; var graphics: igpgraphics; rect, rectbrush: tgprect; brush: cursor; begin graphics: = tgpgraphics. create (canvas. handle); rect. initialize (10, 10,200,150); rectbrush. initialize (rect. X + rect. width Div 8, rect. Y + rect. height Div 8, rect. width Div 4, rect. height Div 4); brush: = tgplineargradientbrush. create (rectbrush, C1, C2, 0); graphics. fillrectangle (brush, rect); graphics. translatetransform (0, rect. height + rect. y); brush: = tgplineargradientbrush. create (rectbrush, C1, C2, 90); graphics. fillrectangle (brush, rect); graphics. translatetransform (rect. width + rect. x,-graphics. transform. offsety); brush: = tgplineargradientbrush. create (rectbrush, C1, C2, 45); graphics. fillrectangle (brush, rect); graphics. translatetransform (0, rect. height + rect. y); brush: = tgplineargradientbrush. create (rectbrush, C1, C2, 135); graphics. fillrectangle (brush, rect); end;