Hello,
I am using the following code to find the image object, extract it, apply contrast and then set it back. But I am not getting any result.
procedure TfrmMain.ApplyContrastToTopmostImage;
const
// Contrast boost applied to the topmost image of the extracted card
// (range: -100..+100, 0 = no change)
CONTRAST_AMOUNT = 90.0;
var
I, TopIdx, TopMost: Integer;
Obj: TPdfObject;
bmp: TIEBitmap;
Applied: Boolean;
begin
if (ImageEnView1.PdfViewer.Objects = nil) or
(ImageEnView1.PdfViewer.Objects.Count = 0) then
Exit;
Application.ProcessMessages;
// Find the image object that is visually topmost (smallest Bounds.Top)
TopMost := MaxInt;
TopIdx := -1;
for I := 0 to ImageEnView1.PdfViewer.Objects.Count - 1 do
begin
Obj := ImageEnView1.PdfViewer.Objects[I];
if (Obj.ObjectType = ptImage) and (Obj.Bounds.Top < TopMost) then
begin
TopMost := Obj.Bounds.Top;
TopIdx := I;
end;
end;
if TopIdx < 0 then
Exit;
Application.ProcessMessages;
// Extract the image, boost contrast and write it back
bmp := TIEBitmap.Create();
Applied := False;
try
if ImageEnView1.PdfViewer.Objects[TopIdx].GetImage( bmp ) then
begin
bmp.Proc.Contrast( CONTRAST_AMOUNT );
// Store the photo as JPEG to keep the PDF compact
ImageEnView1.IO.Params.PDF_Compression := ioPDF_JPEG;
ImageEnView1.IO.Params.JPEG_Quality := 90;
Applied := ImageEnView1.PdfViewer.Objects[TopIdx].SetImage( bmp );
end;
finally
bmp.Free();
end;
if Applied then
ImageEnView1.PdfViewer.ReloadPage(); // required after changing page images
UpdateControls( True );
end;
TIA
Yogi Yang