第二種構建方式: TGPLinearGradIEntBrush.Create(矩形, 顏色1, 顏色2, 漸變模式);
測試效果圖:
測試代碼:
uses GdiPlus;
procedure TForm1.FormPaint(Sender: TObject);
const
C1 = $FFFF0000 ;
C2 = $FF0000FF;
var
Graphics: IGPGraphics;
Rect, RectBrush: TGPRect;
Brush: IGPLinearGradIEntBrush;
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 是默認值
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;