Welcome

首页 / 软件开发 / Delphi / Delphi与DirectX之DelphiX(83): TDIB.FilterLine()、FilterRect();

Delphi与DirectX之DelphiX(83): TDIB.FilterLine()、FilterRect();2010-11-08 博客园 万一本例效果图:

代码文件:

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DIB, StdCtrls;
type
TForm1 = class(TForm)
DXPaintBox1: TDXPaintBox;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses TypInfo;
var
dib: TDIB;
f: Integer;
procedure TForm1.Button1Click(Sender: TObject);
const
clr = clRed;
var
w,h,a,b: Integer;
begin
DXPaintBox1.DIB.Assign(dib);
w := DXPaintBox1.ClientWidth;
h := DXPaintBox1.ClientHeight;
a := w div 7;
b := h div 7;
DXPaintBox1.DIB.FilterLine(0, b, w, b, clr, TFilterMode(f));
DXPaintBox1.DIB.FilterLine(0, h-b, w, h-b, clr, TFilterMode (f));
DXPaintBox1.DIB.FilterLine(a, 0, a, h, clr, TFilterMode(f));
DXPaintBox1.DIB.FilterLine(w-a, 0, w-a, h, clr, TFilterMode (f));
DXPaintBox1.DIB.FilterRect(w div 5, h div 5, w div 5*3, h div 5*3, clr, TFilterMode(f));
DXPaintBox1.Repaint;
Text := GetEnumName(TypeInfo(TFilterMode), f);
Inc(f); f := f and 3;
end;
procedure TForm1.FormCreate(Sender: TObject);
const
ImgPath1 = "C:TempDX.jpg";
begin
dib := TDIB.Create;
dib.LoadFromFile(ImgPath1);
DXPaintBox1.DIB.Assign(dib);
DXPaintBox1.Width := dib.Width;
DXPaintBox1.Height := dib.Height;
DXPaintBox1.Repaint;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
dib.Free;
end;
end.