程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> Delphi 與 DirectX 之 DelphiX(20): TDirectDrawSurface.FillRect...

Delphi 與 DirectX 之 DelphiX(20): TDirectDrawSurface.FillRect...

編輯:Delphi

TDirectDrawSurface.Fill();
TDirectDrawSurface.FillRect();
TDirectDrawSurface.FillRectAlpha();
TDirectDrawSurface.FillRectAdd();
TDirectDrawSurface.FillRectSub();
其中 Fill 在前面每個例子中都有用到; 另外注意: 這幾個函數中的顏色格式有點亂:
Fill 與 FillRect 使用的是非 Delphi 的顏色格式, 它們使用的紅色應該是: $FF0000;
FillRectAlpha、FillRectAdd、FillRectSub 可以使用 Delphi 的顏色, 紅色可以是: $0000FF 或 clRed.

  本例效果圖:

  代碼文件:

unit Unit1;
interface
uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, DXDraws, StdCtrls;
type
 TForm1 = class(TForm)
  DXDraw1: TDXDraw;
  Button1: TButton;
  Button2: TButton;
  Button3: TButton;
  Button4: TButton;
  Button5: TButton;
  procedure Button1Click(Sender: TObject);
  procedure Button2Click(Sender: TObject);
  procedure Button3Click(Sender: TObject);
  procedure Button4Click(Sender: TObject);
  procedure Button5Click(Sender: TObject);
  procedure FormCreate(Sender: TObject);
 end;
var
 Form1: TForm1;
implementation
{$R *.dfm}
const
 ImgPath1 = 'C:TempTest.jpg';
procedure TForm1.Button1Click(Sender: TObject);
var
 MySurface: TDirectDrawSurface;
begin
 MySurface := TDirectDrawSurface.Create(DXDraw1.DDraw);
 MySurface.LoadFromFile(ImgPath1);
 DXDraw1.Surface.Fill(0);
 DXDraw1.Surface.Draw(0, 0, MySurface);
 DXDraw1.Flip;
 FreeAndNil(MySurface);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
 MySurface: TDirectDrawSurface;
 r: TRect;
begin
 MySurface := TDirectDrawSurface.Create(DXDraw1.DDraw);
 MySurface.LoadFromFile(ImgPath1);
 DXDraw1.Surface.Fill(0);
 DXDraw1.Surface.Draw(0, 0, MySurface);
 r := Bounds(10, 10, DXDraw1.Width - 20, DXDraw1.Height - 20);
 DXDraw1.Surface.FillRect(r, $FF0000);
 DXDraw1.Flip;
 FreeAndNil(MySurface);
end;
procedure TForm1.Button3Click(Sender: TObject);
var
 MySurface: TDirectDrawSurface;
 r: TRect;
begin
 MySurface := TDirectDrawSurface.Create(DXDraw1.DDraw);
 MySurface.LoadFromFile(ImgPath1);
 DXDraw1.Surface.Fill(0);
 DXDraw1.Surface.Draw(0, 0, MySurface);
 r := Bounds(10, 10, DXDraw1.Width - 20, DXDraw1.Height - 20);
 DXDraw1.Surface.FillRectAlpha(r, $0000FF, 128);
 DXDraw1.Flip;
 FreeAndNil(MySurface);
end;
procedure TForm1.Button4Click(Sender: TObject);
var
 MySurface: TDirectDrawSurface;
 r: TRect;
begin
 MySurface := TDirectDrawSurface.Create(DXDraw1.DDraw);
 MySurface.LoadFromFile(ImgPath1);
 DXDraw1.Surface.Fill(0);
 DXDraw1.Surface.Draw(0, 0, MySurface);
 r := Bounds(10, 10, DXDraw1.Width - 20, DXDraw1.Height - 20);
 DXDraw1.Surface.FillRectAdd(r, $0000FF, 255);
 DXDraw1.Flip;
 FreeAndNil(MySurface);
end;
procedure TForm1.Button5Click(Sender: TObject);
var
 MySurface: TDirectDrawSurface;
 r: TRect;
begin
 MySurface := TDirectDrawSurface.Create(DXDraw1.DDraw);
 MySurface.LoadFromFile(ImgPath1);
 DXDraw1.Surface.Fill(0);
 DXDraw1.Surface.Draw(0, 0, MySurface);
 r := Bounds(10, 10, DXDraw1.Width - 20, DXDraw1.Height - 20);
 DXDraw1.Surface.FillRectSub(r, $0000FF, 255);
 DXDraw1.Flip;
 FreeAndNil(MySurface);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
 Button1.Caption := '原始圖片';
 Button2.Caption := 'FillRect';
 Button3.Caption := 'FillRectAlpha';
 Button4.Caption := 'FillRectAdd';
 Button5.Caption := 'FillRectSub';
end;
end.


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