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

posted on 2009-01-16 11:13  万一  阅读(2131)  评论(0编辑  收藏  举报