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

GDI+ 紋理筆刷入門:TGPTextureBrush 基礎用法

     編輯:Delphi

TGPTextureBrush 允許使用任意圖像 (BMP、JPG、PNG 等) 作為填充紋理,是實現豐富視覺效果的關鍵工具。最簡單的建構子僅需一個 TGPImage 參數。

建構子語法

TGPTextureBrush.Create(
  image: TGPImage; { 用於筆刷的圖像 }
);

程式碼實作

最精簡範例:載入 JPG 圖片填充整個表單橢圓區域:

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    procedure FormPaint(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
uses GDIPOBJ, GDIPAPI;

procedure TForm1.FormPaint(Sender: TObject);
var
  g: TGPGraphics;
  img: TGPImage;
  tb: TGPTextureBrush;
begin
  g := TGPGraphics.Create(Canvas.Handle);
  img := TGPImage.Create('c:\temp\small.jpg');
  tb := TGPTextureBrush.Create(img);
  g.FillEllipse(tb, 0, 0, Self.ClientWidth, Self.ClientHeight);
  img.Free;
  tb.Free;
  g.Free;
end;

end.

執行效果

紋理筆刷基礎示範

圖像會自動平鋪填充 (預設 WrapModeTile)。實際應用中建議:

  1. 在 FormCreate 載入圖像並建立筆刷,FormDestroy 釋放,避免重複建構開銷
  2. 根據需求設定 WrapMode 與 Transform 矩陣
  3. 注意圖像路徑部署問題,建議使用資源檔或相對路徑
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved