程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
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.

窗體文件:object Form1: TForm1
 Left = 0
 Top = 0
 Caption = 'Form1'
 ClientHeight = 261
 ClientWidth = 221
 Color = clBtnFace
 Font.Charset = DEFAULT_CHARSET
 Font.Color = clWindowText
 Font.Height = -11
 Font.Name = 'Tahoma'
 Font.Style = []
 OldCreateOrder = False
 Position = poDesktopCenter
 OnCreate = FormCreate
 OnPaint = FormPaint
 PixelsPerInch = 96
 TextHeight = 13
 object TrackBar1: TTrackBar
  Left = 0
  Top = 167
  Width = 113
  Height = 45
  TabOrder = 0
  OnChange = TrackBar1Change
 end
 object TrackBar2: TTrackBar
  Left = 108
  Top = 167
  Width = 113
  Height = 45
  TabOrder = 1
  OnChange = TrackBar2Change
 end
 object RadioGroup1: TRadioGroup
  Left = 8
  Top = 192
  Width = 206
  Height = 61
  Caption = 'RadioGroup1'
  TabOrder = 2
  OnClick = RadioGroup1Click
 end
end

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