随笔 - 2146  文章 - 97 评论 - 11767 trackbacks - 253


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.


posted on 2009-01-15 10:07  万一  阅读(...)  评论(...编辑  收藏