Recent

Author Topic: TImage problem with scaling  (Read 2628 times)

Firebird

  • New Member
  • *
  • Posts: 26
TImage problem with scaling
« on: April 05, 2024, 03:22:50 pm »
I have generated a form that is to show the status of certain fields by bitmaps (see attached screenshot). The TImage(s) are filled from an TImageList instance that holds images at 16x16 and 22x22 pixel resolutions. When I assign the images to the form only the 16x16 pixel resolution is depicted there. What am I doing wrong?

The function doing the assignment looks like:

procedure TForm25.ShowData(alabel: TLabel; show_label: integer; aimage: TImage; show_image: integer; image_no: integer);
var
  aRect : TRect;
begin
  if (show_label = 0) then
  begin
    alabel.Enabled := False;
    aimage.Visible := False;
  end
  else if (show_label = 1) then
  begin
    alabel.Enabled := True;
    ImageList1.GetBitmap(image_no, TCustomBitmap(aimage.Picture.Bitmap));

    aRect := Rect(aimage.Left, aimage.Top, aimage.Left+aimage.Width, aimage.Top+aimage.Height);
    aimage.Picture.Bitmap.Canvas.StretchDraw(aRect, aimage.Picture.Bitmap);

    aimage.Visible := True;
  end
end;       

wp

  • Hero Member
  • *****
  • Posts: 12761
Re: TImage problem with scaling
« Reply #1 on: April 05, 2024, 05:41:04 pm »
What am I doing wrong?
No idea since I don't know what you are doing beyond that code excerpt. Please prepare a small project showing the issue, and upload it here (under "Attachment and other options", pack the pas, lfm, lpi, and lpr files into a common zip, no compilier-generated files).

And what do you mean with "scaling"? Scaling the form and the images when the monitor resolution changes?

What is your Lazarus version? If you work with v3.0 or newer then TImage has Images and ImageIndex properties; this way LCL scaling of images is much easier - see attached project and the screenshots take from it at 96ppi (100%) and 120ppi (125%)
« Last Edit: April 05, 2024, 06:02:54 pm by wp »

Firebird

  • New Member
  • *
  • Posts: 26
Re: TImage problem with scaling
« Reply #2 on: April 06, 2024, 12:42:27 pm »
Thank you for your feedback. Pls. find attached the sample project. I am using Lazarus 2.2.4 and would like to stick to that version.
The retrieved bitmaps (right column) should have the same resolution (size) as the bitmaps on the left side. What I am doing wrong?

wp

  • Hero Member
  • *****
  • Posts: 12761
Re: TImage problem with scaling
« Reply #3 on: April 07, 2024, 12:41:28 am »
I still don't know whether you are concerned about LCLscaling of images (i.e. scaling of image size when the monitor resolution changes). If you are, I am missing that ImageList.Scaled has not been set to true - this would activate LCLScaling for the image list.

If, on the other hand, you only want to extract a specific image size from the image list, you can use the Resolution[ImageSize] property of the ImageList:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   ImageList1.Resolution[22].GetBitmap(0, Image1.Picture.Bitmap);
  4.   ImageList1.Resolution[22].GetBitmap(1, Image2.Picture.Bitmap);
  5. end;
The "[22]" refers to the requested image size.

Firebird

  • New Member
  • *
  • Posts: 26
Re: TImage problem with scaling
« Reply #4 on: April 07, 2024, 01:32:49 pm »
Thank you very much for the explanation WP. That really helped me. I am fine now.

 

TinyPortal © 2005-2018