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:\Temp\Test.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.