2

I'm using TImage components in order to display image files. However the pictures look blurry when displayed in high-DPI monitors. If I use high-resolution images, they are stretched in normal monitors and looks bad.

I'm aware Delphi 10.4 has built-in TVirtualImage component. I'm looking for a workaround for Delphi 10.3.3 VCL applications.

Xel Naga
  • 826
  • 11
  • 28

1 Answers1

3
  • put your image files with different resolutions into a TImageCollection

  • add a TVirtualImageList onto your form and set its Width and Height as needed

  • add that image to the TVirtualImageList

  • add a method UpdateImage to your form with the following content:

    Image1.Picture.Bitmap := nil;
    VirtualImageList1.GetBitmap(0, Image1.Picture.Bitmap);
    
  • call UpdateImage in the forms OnCreate and OnAfterMonitorDpiChanged handler

Uwe Raabe
  • 45,288
  • 3
  • 82
  • 130
  • 1
    So this basically requires the OP to use Photoshop (say) to create different versions of the original image. It would be more convenient if the OP only had to provide one high-res version which is downscaled at runtime. – Andreas Rejbrand Aug 09 '21 at 13:07
  • 1
    No, the TVirtualImageList does the scaling internally. It is just that automatically scaling pixel images doesn't always give the best results. F.i. a highly detailed 256px image will most likely look poor when scaled down to 16px. That is why you should provide different resolutions in the image collection, but you don't have to provide all resolutions that may be needed anytime. – Uwe Raabe Aug 09 '21 at 13:33
  • 2
    Of course you can provide only one high-res image and let that be scaled down with the above approach. If that satisfies your needs, fine. – Uwe Raabe Aug 09 '21 at 13:34
  • @UweRaabe Thank you, it works! However transparent PNG image's background is white. Image's Transparent property is True. Any idea? – Xel Naga Aug 09 '21 at 14:33
  • 1
    Unfortunately, no. You can get hands directly on the PNG images stored in the collection (if they actually are PNG, of course), but that will remove the automatic scaling mechanism and you are tied to the available image sizes. – Uwe Raabe Aug 09 '21 at 18:27