ImageEn, unit iexPdfiumCore

TPdfObject.GetImage

TPdfObject.GetImage


Declaration

function GetImage(Dest: TIEBitmap): Boolean; overload;
function GetImage(): TBitmap; overload;


Description

Return a bitmap of an image object of the current page (when ObjectType is ptImage).

Note:
Use SetImage to replace the image of an object
Unlike GetImage will not fail for an unknown image/compression type


Examples

// Show preview of an image in the current PDF page
ImageEnView1.PdfViewer.Objects[idx].GetImage( ImageEnView2.IEBitmap );
ImageEnView2.Update();


// Save all images in the page to file
for i := 0 to ImageEnView1.PdfViewer.Objects.Count - 1 do
  if ImageEnView1.PdfViewer.Objects[i].ObjectType = ptImage then
  begin
    bmp := TIEBitmap.Create();
    if ImageEnView1.PdfViewer.Objects[i].GetImage( bmp ) then
      bmp.SaveToFile( 'D:\PDFTest\Object_' + i.ToString + '.png' );
    bmp.Free;
  end;


// Reduce the size of the PDF file by lowering the quality of the images (B is a TIEBitmap)
for i := 0 to ImageEnView1.PdfViewer.Objects.Count - 1 do
begin
  oPDF := ImageEnView1.PdfViewer.Objects[i];
  if (oPDF.ObjectType = ptImage) then
  begin
    B := TIEBitmap.Create();
    try
      if oPDF.GetImage( B ) then
      begin
        B.Resample( 0.5 );
        oPDF.SetImage(B);
       end;
    finally
      B.Free;
    end;
  end;
end;
ImageEnView1.PdfViewer.ReloadPage();

// Same as above but B is a TBitmap (must add iexHelperFunctions to your uses clause for TBitmap.Proc)
for i := 0 to ImageEnView1.PdfViewer.Objects.Count - 1 do
begin
  oPDF := ImageEnView1.PdfViewer.Objects[i];
  if (oPDF.ObjectType = ptImage) then
  begin
    B := oPDF.GetImage();
    if B <> nil then
    try
      B.Proc.Resample( 0.5 );
      oPDF.SetImage(B);
    finally
      B.Free;
    end;
  end;
end;
ImageEnView1.PdfViewer.ReloadPage();


See Also

SetImage
GetImageRaw