程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> 再學GDI+[68]: 路徑畫刷(8)

再學GDI+[68]: 路徑畫刷(8)

編輯:Delphi

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.

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved