DelphiX的組件面板上, 第二個就是TDXDIB;
TDXDIB.DIB是TDXDIB的唯一屬性(其他是TComponent 固有的);
TDXDIB.DIB屬性是一個TDIB對象;
TDIB和TBitmap一樣都直接繼承自TGraphic, 是一個圖片容器, 它還有個別名: TDIBitmap;
TDIB和TDXDraw.Surface還有 TDXImageList中的元素(TPictureCollectionItem)功能都差不多, 不過它更強大.
使用TDIB需要uses DIB單元;
但如果添加了TDXDIB組件, DIB 單元會自動添加, 並可以在設計時裝載圖片.
本例測試了TDIB的模糊圖像的功能, 效果圖如下:
代碼文件:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DIB, DXDraws, StdCtrls;
type
TForm1 = class(TForm)
DXDraw1: TDXDraw;
DXDIB1: TDXDIB;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
const
ImgPath1 = 'C:\Temp\DelphiX.bmp';
procedure TForm1.Button1Click(Sender: TObject);
begin
DXDraw1.Surface.LoadFromFile(ImgPath1);
DXDraw1.Flip;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
DXDIB1.DIB.LoadFromFile(ImgPath1);
DXDIB1.DIB.Blur(32, 1);
DXDraw1.Surface.LoadFromDIB(DXDIB1.DIB);
DXDraw1.Flip;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
DXDIB1.DIB.LoadFromFile(ImgPath1);
DXDIB1.DIB.Blur(32, 6);
DXDraw1.Surface.LoadFromDIB(DXDIB1.DIB);
DXDraw1.Flip;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
DXDIB1.DIB.LoadFromFile(ImgPath1);
DXDIB1.DIB.Blur(4, 2);
DXDraw1.Surface.LoadFromDIB(DXDIB1.DIB);
DXDraw1.Flip;
end;
end.
窗體文件:
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 151
ClientWidth = 280
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object DXDraw1: TDXDraw
Left = 8
Top = 8
Width = 265
Height = 105
AutoInitialize = True
AutoSize = True
Color = clBlack
Display.FixedBitCount = False
Display.FixedRatio = True
Display.FixedSize = True
Options = [doAllowReboot, doWaitVBlank, doCenter, do3D, doDirectX7Mode, doHardware, doSelectDriver]
SurfaceHeight = 105
SurfaceWidth = 265
TabOrder = 0
Traces = <>
end
object Button1: TButton
Left = 8
Top = 119
Width = 60
Height = 25
Caption = 'Button1'
TabOrder = 1
OnClick = Button1Click
end
object Button2: TButton
Left = 76
Top = 119
Width = 60
Height = 25
Caption = 'Button2'
TabOrder = 2
OnClick = Button2Click
end
object Button3: TButton
Left = 144
Top = 119
Width = 60
Height = 25
Caption = 'Button3'
TabOrder = 3
OnClick = Button3Click
end
object Button4: TButton
Left = 213
Top = 119
Width = 60
Height = 25
Caption = 'Button4'
TabOrder = 4
OnClick = Button4Click
end
object DXDIB1: TDXDIB
Left = 240
Top = 16
end
end