IGPLinearGradIEntBrush.Blend 屬性對應一個 IGPBlend 對象;
TGPBlend.Create(Factors, Positions); 中的兩個參數都是 Single 類型的數組,
Factors 顏色強度因子, Positions 是位置偏移比例.
對於兩種顏色的漸變, 上面兩個數組都應是三個元素構成; 默認效果是 [0, 0.5, 1].
測試效果圖:
測試代碼:
uses GdiPlus;
procedure TForm1.FormPaint(Sender: TObject);
var
Graphics: IGPGraphics;
Rect: TGPRectF;
Brush: IGPLinearGradIEntBrush;
StringFormat: IGPStringFormat;
Font: IGPFont;
BrushText: IGPSolidBrush;
begin
Graphics := TGPGraphics.Create(Canvas.Handle);
Rect.Initialize(20 , 10, ClIEntWidth - 40, 30);
Brush := TGPLinearGradIEntBrush.Create(Rect, $FFFF0000, $FF0000FF, 0);
StringFormat := TGPStringFormat.Create;
StringFormat.Alignment := StringAlignmentCenter;
StringFormat.LineAlignment := StringAlignmentFar;
Font := TGPFont.Create(Canvas.Handle);
BrushText := TGPSolidBrush.Create($FFCCCCCC);
Brush.Blend := TGPBlend.Create([0, 0.5, 1], [0, 0.5, 1]);
Graphics.FillRectangle(Brush, Rect);
Graphics.DrawString('[0, 0.5, 1], [0, 0.5, 1]', Font, Rect, StringFormat, BrushText);
//
Brush.Blend := TGPBlend.Create([0, 0.5, 1], [0, 0.2, 1]);
Graphics.TranslateTransform(0, Rect.Y + Rect.Height);
Graphics.FillRectangle(Brush, Rect);
Graphics.DrawString('[0, 0.5, 1], [0, 0.2, 1]', Font, Rect, StringFormat, BrushText);
Brush.Blend := TGPBlend.Create([0, 0.5, 1], [0, 0.8, 1]);
Graphics.TranslateTransform(0, Rect.Y + Rect.Height);
Graphics.FillRectangle(Brush, Rect);
Graphics.DrawString('[0, 0.5, 1], [0, 0.8, 1]', Font, Rect, StringFormat, BrushText);
//
Brush.Blend := TGPBlend.Create([0, 0.2, 1], [0, 0.5, 1]);
Graphics.TranslateTransform(0, Rect.Y + Rect.Height);
Graphics.FillRectangle(Brush, Rect);
Graphics.DrawString('[0, 0.2, 1], [0, 0.5, 1]', Font, Rect, StringFormat, BrushText);
Brush.Blend := TGPBlend.Create([0, 0.8, 1], [0, 0.5, 1]);
Graphics.TranslateTransform(0, Rect.Y + Rect.Height);
Graphics.FillRectangle(Brush, Rect);
Graphics.DrawString('[0, 0.8, 1], [0, 0.5, 1]', Font, Rect, StringFormat, BrushText);
//
Brush.Blend := TGPBlend.Create([0, 0.2, 1], [0, 0.2, 1]);
Graphics.TranslateTransform(0, Rect.Y + Rect.Height);
Graphics.FillRectangle(Brush, Rect);
Graphics.DrawString('[0, 0.2, 1], [0, 0.2, 1]', Font, Rect, StringFormat, BrushText);
Brush.Blend := TGPBlend.Create([0, 0.8, 1], [0, 0.8, 1]);
Graphics.TranslateTransform(0, Rect.Y + Rect.Height);
Graphics.FillRectangle(Brush, Rect);
Graphics.DrawString('[0, 0.8, 1], [0, 0.8, 1]', Font, Rect, StringFormat, BrushText);
//
Brush.Blend := TGPBlend.Create([0, 0.2, 1], [0, 0.8, 1]);
Graphics.TranslateTransform(0, Rect.Y + Rect.Height);
Graphics.FillRectangle(Brush, Rect);
Graphics.DrawString('[0, 0.2, 1], [0, 0.8, 1]', Font, Rect, StringFormat, BrushText);
Brush.Blend := TGPBlend.Create([0, 0.8, 1], [0, 0.2, 1]);
Graphics.TranslateTransform(0, Rect.Y + Rect.Height);
Graphics.FillRectangle(Brush, Rect);
Graphics.DrawString('[0, 0.8, 1], [0, 0.2, 1]', Font, Rect, StringFormat, BrushText);
end;