ImageEn, unit iexPdfiumCore |
|
TPdfObject.SetImage
Declaration
function SetImage(Bitmap: TIEBitmap): Boolean; overload;
function SetImage(Bitmap: TBitmap): Boolean; overload;
Description
Replaces the bitmap of an image object in the current page (when
ObjectType is ptImage).
Note:
◼Use
GetImage to get the image of an object
◼You must call ImageEnView1.PdfViewer.ReloadPage() after changing page images
// Replace all the images in the page
bmp := TIEBitmap.Create();
try
bmp.LoadFromFile( 'D:\MyLogo.jpg' );
for i := 0 to ImageEnView1.PdfViewer.Objects.Count - 1 do
if ImageEnView1.PdfViewer.Objects[i].ObjectType = ptImage then
begin
if ImageEnView1.PdfViewer.Objects[i].SetImage( bmp ) = False then
BREAK;
end;
finally
bmp.Free;
ImageEnView1.PdfViewer.ReloadPage();
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
◼GetImage
◼GetImageRaw
◼AddImage