Icons in imagelist for dynamically created components in high DPI screens lazarus / 31-LCL ---------------------------------------------------------------------- simsee · 2025-05-29 16:10 I have to make an application where some dynamically created components must use icons of different sizes, in order to adapt to screens with different high dpi. While it is clear to me how to proceed when working with components created at design time, in which case I can use the image list editor to load icons of different sizes, how can I obtain the same result via code for dynamically created components? I attach a concrete example with a TTreeView that uses an ImageList to store icons for nodes, loaded from a resource file created with lazres, that contains three icons, of dimensions 16x16, 24x24, 32x32. Thanks. ---------------------------------------------------------------------- wp · 2025-05-29 16:43 There are a few things which are missing: Set the ImageList.Scaled property to true, otherwise the ImageList will not change to the required image size when resolution changes.Before adding images at the various resolutions you must "register" the additional resolutions so that the ImageList "knows" which sizes it must provide. Call the ImageList RegisterResolutions method and give the provided image widths as an array: ImageList.RegisterResolutions([16, 24, 32])Finally, do not add the differenty-sized images one by one, but in one go - there is method AddMultipleResolutions for it; otherwise the images will get different image indices. Again, add the images as an array. The images must be ordered by size, from smallest to largest. Unfortunately, there is no such method for adding images from a resouce. Therefore, you must first load the images from the resource into temporary bitmaps and then pass these to the AddMultipleresolutions callCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormCreate(Sender: TObject);var  bmp16, bmp24, bmp32: TCustomBitmap;begin  ImageList:=TImageList.Create(self);  ImageList.Scaled := true;  ImageList.RegisterResolutions([16, 24, 32]);   bmp16 := TPortableNetworkGraphic.Create;  bmp24 := TPortableNetworkGraphic.Create;  bmp32 := TPortableNetworkGraphic.Create;  try    bmp16.LoadFromResourceName(HINSTANCE, 'cc_class');    bmp24.LoadFromResourceName(HINSTANCE, 'cc_class_150');    bmp32.LoadFromResourceName(HINSTANCE, 'cc_class_200');    ImageList.AddMultipleResolutions([bmp16, bmp24, bmp32]);  finally    bmp32.Free;    bmp24.Free;    bmp16.Free;  end;   ...The attached screenshots show your demo at 96ppi and 144ppi after this modification ---------------------------------------------------------------------- simsee · 2025-05-29 17:53 Dear Wp, thanks for the usual great explanation. What is not clear to me is: how is the image selected based on the DPI of the screen? ---------------------------------------------------------------------- wp · 2025-05-29 18:13 It depends on what you assign to the ImagesWidth of the TreeView (i.e., the control which uses the imagelist): When you have here the default value, 0, the images which have the same size as specified in the ImageList.Width and .Height properties are used at 96 ppi. If if ImagesWidth is different this is used as the 96ppi width. When then the resolution changes to, say, 144 ppi (150% of 86 ppi) the 150% images are used. And the same is for 200% (192 ppi). And when you have an intermediate resolution? Not 100% sure, but I guess the image list selects the size which is closest. Or, if you provide a handler for ImageList.GetWidthForPPI, you can even force it to scale to intermediate resolutions (with some loss in quality, though). See also https://wiki.freepascal.org/TImageList#How_to_create_a_multi- resolution_ImageList_in_the_application