Page 1 of 1

Check if Image needs resizing on insert

Posted: Wed Apr 01, 2020 1:29 pm
by spang@xperttimer.de
In v17 of RichView I used the following code snipped to check if an image needs to be resized before inserting it.

Code: Select all

 function IsImageTooLarge(gr: TGraphic): Boolean;
 begin
  Result := (MaxImageSize>0) and
    ((gr.Width > TRVStyle.GetAsPixelsEx(MaxImageSize, rvstuPixels)) or
     (gr.Height> TRVStyle.GetAsPixelsEx(MaxImageSize, rvstuPixels)));
 end;
With v18 it complains about "TRVStyle.GetAsPixelsEx" being undeclared (E1081). What would be the suggested way to do this in v18?

Re: Check if Image needs resizing on insert

Posted: Wed Apr 01, 2020 6:04 pm
by Sergey Tkachenko
TRVStyle.GetAsPixelsEx(MaxImageSize, rvstuPixels) simple returned MaxImageSize (this is a "conversion" from pixels to pixels).

So you can simply write:

Code: Select all

function IsImageTooLarge(gr: TGraphic): Boolean;
 begin
  Result := (MaxImageSize>0) and
    ((gr.Width > MaxImageSize) or
     (gr.Height> MaxImageSize));
 end;
In the original code (TrvActionInsertPicture.IsImageTooLarge from RichViewActions), GetAsPixelsEx made sense because MaxImageSize is measured not necessary in pixels; it is measured in RVAControlPanel.UnitsProgram (pixels or twips).

Please note that in the new version of TRichView, gr.Width, gr.Height, and rvActionInsertPicture.MaxImageSize are measured in logical pixels, i.e. pixels at 96 DPI. When displaying, image will be scaled proportionally to the screen DPI.