Check if Image needs resizing on insert

General TRichView support forum. Please post your questions here
Post Reply
spang@xperttimer.de
Posts: 4
Joined: Mon Dec 09, 2019 1:18 pm

Check if Image needs resizing on insert

Post 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?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Check if Image needs resizing on insert

Post 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.
Post Reply