程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> GdiPlus[18]: IGPPathGradientBrush 之 CenterColor、Surround

GdiPlus[18]: IGPPathGradientBrush 之 CenterColor、Surround

編輯:Delphi

最簡單的 IGPPathGradIEntBrush 就是有一個中心顏色和一組周邊顏色的漸變.

  這裡牽扯到 CenterColor、SurroundColors 屬性和 SetSurroundColors 方法.

  測試一效果圖:

GdiPlus[18]: IGPPathGradientBrush 之 CenterColor、SurroundColors

  測試一代碼:

//使用 SetSurroundColors 方法設置周邊色組:  
uses GdiPlus, GdiPlusHelpers; 
 
procedure TForm1.FormPaint(Sender: TObject); 
var 
 Brush: IGPPathGradIEntBrush; 
 Rect: TGPRect; 
 Path: IGPGraphicsPath; 
begin 
 Rect.Initialize(10 , 10, 200, 150); 
 Path := TGPGraphicsPath.Create; 
 Path.AddEllipse(Rect); 
 
 Brush := TGPPathGradIEntBrush.Create(Path); 
 Brush.CenterColor := $FF00FF00; 
 Brush.SetSurroundColors([$FF000000]); 
 
 Canvas.ToGPGraphics.FillEllipse(Brush, Rect); 
end; 
 
//使用 SurroundColors 屬性設置周邊色組: 
uses GdiPlus, GdiPlusHelpers; 
 
procedure TForm1.FormPaint(Sender: TObject); 
var 
 Brush: IGPPathGradIEntBrush; 
 Rect: TGPRect; 
 Path: IGPGraphicsPath; 
 Colors: IGPColors; 
begin 
 Rect.Initialize(10, 10, 200, 150); 
 Path := TGPGraphicsPath.Create; 
 Path.AddEllipse(Rect); 
 
 Brush := TGPPathGradIEntBrush.Create(Path); 
 Brush.CenterColor := $FF00FF00; 
 
 Colors := TGPArray<TGPColor>.Create(1); 
 Colors[0] := $FF000000; 
 Brush.SurroundColors := Colors; 
 
 Canvas.ToGPGraphics.FillEllipse(Brush, Rect); 
end; 

  測試二效果圖:

GdiPlus[18]: IGPPathGradientBrush 之 CenterColor、SurroundColors

  測試二代碼:

//使用 SetSurroundColors 方法設置周邊色組: 
uses GdiPlus, GdiPlusHelpers; 
 
procedure TForm1.FormPaint(Sender: TObject); 
var 
 Brush: IGPPathGradIEntBrush; 
 Rect: TGPRect; 
 Path: IGPGraphicsPath; 
begin 
 Rect.Initialize(10, 10, 200, 150); 
 Path := TGPGraphicsPath.Create; 
 Path.AddRectangle(Rect); 
 
 Brush := TGPPathGradIEntBrush.Create(Path); 
 Brush.CenterColor := $FFFFFFFF; 
 Brush.SetSurroundColors([$FFFF0000, $FF00FF00, $FF0000FF, $FFFFFF00]); 
 
 Canvas.ToGPGraphics.FillRectangle(Brush, Rect); 
end; 
 
//使用 SurroundColors 屬性設置周邊色組: 
uses GdiPlus, GdiPlusHelpers; 
 
procedure TForm1.FormPaint(Sender: TObject); 
var 
 Brush: IGPPathGradIEntBrush; 
 Rect: TGPRect; 
 Path: IGPGraphicsPath; 
 Colors: IGPColors; 
begin 
 Rect.Initialize(10, 10, 200, 150); 
 Path := TGPGraphicsPath.Create; 
 Path.AddRectangle(Rect); 
 
 Brush := TGPPathGradIEntBrush.Create(Path); 
 Brush.CenterColor := $FFFFFFFF; 
 
 Colors := TGPArray<TGPColor>.Create(4); 
 Colors[0] := $FFFF0000; 
 Colors[1] := $FF00FF00; 
 Colors[2] := $FF0000FF; 
 Colors[3] := $FFFFFF00; 
 Brush.SurroundColors := Colors; 
 
 Canvas.ToGPGraphics.FillRectangle(Brush, Rect); 
end; 


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