Fred
Fred

Reputation: 25

How to resize a TImage correctly when running on low-res or Hi-res monitor systems

My application is 64 bit using Berlin 10.1. My VCL form has two panels (L and R). Panel-L holds a TMemo, panel-R holds a TImage. Development was on a 1920 x 1080 monitor. Following Zarko Gajic: I have set the PPI value for the form on 120 (i.e. not 96 = default) and Form.Scale = true; Other form properties I used: wsNormal, alNone, akLeft, akTop. Fot the panels: panel-L: alLeft, autosize = false, and panel-R: alCLient, autosize = false. For the image I used: Image.autosize = false, Image.Stretch = true, Image.Width / .Height = 600 / 500 in design mode (on my form).

In Project > Options > Applications I use:

When I run the .exe file on a system with 2x the screen resolution the memo scales correctly (Although I had a problem with the font / text running off the memo frame). But the Image keeps its real 600 / 500 size. I.e. it shrinks quite a lot. When running on 4K (I don't have that, but others do), I expect that the image will shrink to stamp size ... To make it more complex, the program should also run on older systems, down to 1366 x 768 res. Note that my TImage has to load many different images (jpg) of different sizes (but never larger than 600 x 500) during run time. Coding for scaling using the screen.height or . width of the user system (relative to my resolution doesn't help). I tried:

Factor := min(screen.Width / 1920, screen.Height / 1080); // single
k := trunc(factor*100);
btn1.ScaleBy(k,100);  // this works for a Tbutton, not for Timage

I noticed that the .stretch property tends to really mess up small JPGs (<< 600 x 500). I tried to study many articles on the internet, but I am afraid that I cannot solve it. I am not a professional programmer. Can anybody offer some help or refer to an article (preferably with some code) that answers my question?

What I found is that this: When I

  1. put my TImage on a Tpanel of the same dimensions (width, Height)of the TImage, and
  2. set the alignment of both to alClient

Then the image resizes when used on a monitor with different resolution. In my case it won't work as I have more images. But perhaps this is way forward: What does the the Tpanel do upon resizing with the image? Can I find code to appy to the TImage (without the requirement of a separate panel?)

Upvotes: 0

Views: 16

Answers (0)

Related Questions