PDFium Delphi Component Docs

GetImageObjectRenderedBitmap method

Component: TPdf  ·  Unit: PDFium
Renders one image page object on its own and returns the decoded pixels as a caller-owned bitmap

Syntax

function GetImageObjectRenderedBitmap(Index: Integer): TBitmap;

IndexInteger. Zero-based index of an image page object, in the range 0 .. ObjectCount - 1. An object of another type raises an EPdfError (Image object required)
ResultTBitmap. A newly created bitmap the caller owns and must free, or nil when the native call produces no bitmap

Description

Renders just that image object through the native renderer (FPDFImageObj_GetRenderedBitmap) with its current matrix, colour space and masks applied — the result shows the image as the page shows it, including soft masks, stencil keys and colour conversions, which the raw samples available through Image do not carry

The render lock is held for the native call, so it is safe against concurrent rendering on the same component. The native bitmap is converted and destroyed before returning; the resulting TBitmap belongs to the caller

The call requires the current page to be active, the object at Index to be of type otImage (check ObjectType), and a PDFium build that exports the per-image rendering entry point; otherwise an EPdfError is raised (Rendered image object bitmaps are not available)

A nil result is not an abort condition: when the native call yields no bitmap, a caller can fall back to cropping a full-page render with the bounds from ObjectBounds

Remarks

Example

var
  Bmp: TBitmap;
begin
  if Pdf1.ObjectType[7] = otImage then
  begin
    Bmp := Pdf1.GetImageObjectRenderedBitmap(7);
    if Bmp <> nil then
      try
        Image1.Picture.Bitmap.Assign(Bmp);
        // use Bmp for export, comparison or recognition
      finally
        Bmp.Free;
      end;
  end;
end;

See Also

GetTextObjectRenderedBitmap, ObjectBitmap, ObjectType, ObjectBounds, ImageInfo