PDFium Delphi Component 文件

AddImage 方法

元件: TPdf  ·  單元: PDFium
將檔案中的影像插入到目前 PDF 頁面。內部使用 TPicture.LoadFromFile,因此可接受 VCL 或 LCL 圖形單元註冊的任何影像格式,包括 BMP、透過 Vcl.Imaging.PngImage / LCL TPortableNetworkGraphic 的 PNG、JPG 等。座標位於 PDF 使用者空間(原點在頁面左下角);Width 和 Height 是放置尺寸,以使用者單位表示,而不是來源影像的像素大小

Syntax

procedure AddImage(const FileName: string; X, Y, Width, Height: Double);

FileNamestring。影像檔的完整路徑。可接受任何已向 VCL/LCL 圖形系統註冊的格式(BMP、PNG、JPG 等)

 

procedure AddImage(Bitmap: TBitmap; X, Y, Width, Height: Double);

BitmapTBitmap。預先載入且 PixelFormat = pf32bit 的點陣圖。不得為 nil,否則會引發 EPdfError

Description

AddImage 會以指定的位置與大小將影像放到目前的 PDF 頁面上。共有兩個多載:一個直接從檔案路徑載入影像,另一個接受預先建好的 TBitmap 物件

以檔案為基礎的多載會在內部使用 TPicture.LoadFromFile,因此支援任何已向 VCL 或 LCL 圖形系統註冊的影像格式 — 包括 BMP、PNG(透過 Vcl.Imaging.PngImage 或 LCL 的對等項目)、JPEG 與其他格式。只要在呼叫此方法前,確定專案的 uses 子句已包含相關單元即可

點陣圖多載接受 PixelFormat = pf32bit 的 TBitmap。當點陣圖已存在記憶體中(例如來自離螢幕算繪步驟)時特別有用,可避免經由磁碟或 TPicture 的往返。傳入 nil 點陣圖會引發 EPdfError 例外

X 與 Y 參數以 PDF 使用者單位指定影像放置矩形的左下角(原點在頁面左下,Y 軸向上遞增)。Width 與 Height 控制頁面上的算繪大小;無論來源影像的像素解析度為何,都會縮放至符合這些尺寸

Example

// Place a PNG file at (72, 600), rendered 200 x 150 pt on the page
Pdf1.NewPage(595, 842);
Pdf1.AddImage('C:\Images\logo.png', 72, 600, 200, 150);

// Add a pre-built 32-bit bitmap
var
  Bmp: TBitmap;
begin
  Bmp := TBitmap.Create;
  try
    Bmp.PixelFormat := pf32bit;
    Bmp.LoadFromFile('C:\Images\photo.bmp');
    Pdf1.AddImage(Bmp, 72, 400, 300, 200);
  finally
    Bmp.Free;
  end;
end;

See Also

AddPicture, AddJpegImage, AddText