SetBlendTriangularShaped、SetBlendBellShape
本例效果圖(顏色失真嚴重, 因為 GIF 最多只能接受 256 中顏色):
代碼文件:unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
TrackBar1: TTrackBar;
TrackBar2: TTrackBar;
RadioGroup1: TRadioGroup;
procedure FormCreate(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure RadioGroup1Click(Sender: TObject);
procedure TrackBar1Change(Sender: TObject);
procedure TrackBar2Change(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses GDIPOBJ, GDIPAPI;
procedure TForm1.FormCreate(Sender: TObject);
begin
TrackBar1.Max := 100;
TrackBar2.Max := 100;
TrackBar1.Position := TrackBar1.Max;
TrackBar2.Position := TrackBar2.Max;
TrackBar1.ShowSelRange := False;
TrackBar2.ShowSelRange := False;
TrackBar1.Height := 23;
TrackBar2.Height := 23;
RadioGroup1.Items.CommaText := 'BlendTriangularShape, SetBlendBellShape';
RadioGroup1.ItemIndex := 0;
DoubleBuffered := True;
end;
procedure TForm1.FormPaint(Sender: TObject);
const
colors: array[0..0] of TGPColor = (aclRed);
var
g: TGPGraphics;
path: TGPGraphicsPath;
pb: TGPPathGradientBrush;
num: Integer;
begin
g := TGPGraphics.Create(Canvas.Handle);
path := TGPGraphicsPath.Create;
path.AddRectangle(MakeRect(30,10,160,150));
pb:= TGPPathGradientBrush.Create(path);
num := Length(colors);
pb.SetSurroundColors(@colors, num);
pb.SetCenterColor(aclYellow);
{SetBlendTriangularShape 與 SetBlendBellShape 參數2的默認值都是 1.0}
case RadioGroup1.ItemIndex of
0: pb.SetBlendTriangularShape(TrackBar1.Position/100, TrackBar2.Position/100);
1: pb.SetBlendBellShape(TrackBar1.Position/100, TrackBar2.Position/100);
end;
g.FillPath(pb, path);
pb.Free;
path.Free;
g.Free;
end;
procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
Repaint;
end;
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
Repaint;
end;
procedure TForm1.TrackBar2Change(Sender: TObject);
begin
Repaint;
end;
end.