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

GdiPlus[14]: IGPLinearGradientBrush 之 Blend

編輯:Delphi

 IGPLinearGradIEntBrush.Blend 屬性對應一個 IGPBlend 對象;

  TGPBlend.Create(Factors, Positions); 中的兩個參數都是 Single 類型的數組,

  Factors 顏色強度因子, Positions 是位置偏移比例.

  對於兩種顏色的漸變, 上面兩個數組都應是三個元素構成; 默認效果是 [0, 0.5, 1].

  測試效果圖:

GdiPlus[14]: IGPLinearGradientBrush 之 Blend

  測試代碼:

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; 


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