首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> Delphi

DelphiX 核心元件 TDXPaintBox 與 TDIB 圖像容器詳解

     編輯:Delphi

TDXPaintBox 介紹

TDXPaintBox 類似 TPaintBox 擁有 Canvas,但核心屬性是 DIB: TDIB。設計時可直接載入圖片,運行時動態指派 TDIB 物件。本質上可視為 TImage 的 DirectX 版對應物 (Picture → DIB)。

TDIB 物件

  • 繼承自 TGraphic,別名 TDIBitmap。
  • 功能對應 TDXDraw.Surface、TPictureCollectionItem,但提供豐富影像處理方法 (模糊、旋轉、濾鏡、色彩調整等)。
  • 需 uses DIB;拖放 TDXDIB 元件會自動引入。

範例:載入、縮放、拉伸顯示


unit Unit1;

interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
     Dialogs, DIB, StdCtrls;

type
  TForm1 = class(TForm)
    DXPaintBox1: TDXPaintBox;
    Button1: TButton; Button2: TButton; Button3: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  end;

var Form1: TForm1; W, H: Integer;

implementation
{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
const ImgPath = 'C:\Temp\DX.jpg';
begin
  DXPaintBox1.Left := 0; DXPaintBox1.Top := 0;
  DXPaintBox1.DIB.LoadFromFile(ImgPath);
  W := DXPaintBox1.DIB.Width; H := DXPaintBox1.DIB.Height;
  DXPaintBox1.Width := W; DXPaintBox1.Height := H;
  DXPaintBox1.Stretch := True;  // 自動拉伸填滿控件
end;

procedure TForm1.Button1Click(Sender: TObject);
begin DXPaintBox1.Width := W div 2; DXPaintBox1.Height := H div 2; end;

procedure TForm1.Button2Click(Sender: TObject);
begin DXPaintBox1.Width := ClientWidth; DXPaintBox1.Height := ClientHeight; end;

procedure TForm1.Button3Click(Sender: TObject);
begin DXPaintBox1.Width := W; DXPaintBox1.Height := H; end;

end.

表單定義 (DFM 節錄)


object Form1: TForm1
  ClientHeight = 165; ClientWidth = 225
  OnCreate = FormCreate
  object DXPaintBox1: TDXPaintBox
    Left = 8; Top = 8; Width = 81; Height = 73
    AutoStretch = False; Stretch = False
  end
  object Button1: TButton; Left = 23; Top = 132; Caption = 'Half'; end
  object Button2: TButton; Left = 89; Top = 132; Caption = 'Full Client'; end
  object Button3: TButton; Left = 157; Top = 132; Caption = 'Original'; end
end

附加:範例圖片

範例圖片 DX.jpg

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved