PDFium Delphi Component 文件

BitmapCount 属性

组件: TPdf  ·  单元: PDFium
活动页面上图像页面对象的数量,可获取为 VCL TBitmap

语法

property BitmapCount: Integer; // read only

说明

BitmapCount 返回当前活动页面上图像页面对象的数量(PDF 1.7 规范第 8.9 节)。它与索引器 Bitmap[Index] 配对,后者把底层图像流解码为完全渲染的 Delphi TBitmap(32 位 RGBA,可直接用于 Canvas.Draw、剪贴板传输或保存为 PNG/BMP)

当 Active 为 False、PageNumber 无效或页面不包含图像对象时,该值为 0。此计数与 ImageCount 相同;两个属性的区别仅在于索引器的返回类型 — Image[Index] 返回 TPdfImage 记录,其 Data 持有解码后的像素缓冲区,RawData 携带仍处于编码状态的图像流,而 Bitmap[Index] 把该缓冲区包装为由调用方持有的托管 VCL TBitmap

典型的循环是 for I := 0 to Pdf.BitmapCount - 1 do,随后访问 Pdf.Bitmap[I]。每次访问都会分配新的 TBitmap 并复制像素 — 不要在紧凑的渲染循环中调用它;需要重复使用时应缓存位图。用完后请释放每个返回的位图,以便及时释放 GDI 资源

备注

示例

var I: Integer;
var Bmp: TBitmap;
for I := 0 to Pdf1.BitmapCount - 1 do
begin
  Bmp := Pdf1.Bitmap[I];
  try
    Bmp.SaveToFile(Format('image_%d.bmp', [I]));
  finally
    Bmp.Free;
  end;
end;

参见

Bitmap, ImageCount, Image, ObjectBitmap