markus_ja
markus_ja

Reputation: 2951

How to assign a picture from a TImageList to an TImage?

I am just using the trial version of AppMethod 1.17 aka Delphi 10 Seattle. Therefore I cannot look into the source code.

In VCL I used TImageList.Draw(), but with the new TMultiResBitmap class I don't know how to use it.

Upvotes: 3

Views: 7242

Answers (2)

Kromster
Kromster

Reputation: 7397

Another approach would be to add the bitmap into the MultiResBitmap of the TImage:

var
  sz: TSize;
  bmpSrc, bmpTgt: TBitmap;

...

// Obtain the bitmap (e.g. from ImageList in data-module)
sz := TSize.Create(MaxInt, MaxInt); // Pick best size
DataModule1.ImageList1.BestSize(3, sz);
bmpSrc := DataModule1.ImageList1.Bitmap(sz, 3);

// Assign to Image1, to desired scale
bmpTgt := Image1.MultiResBitmap.Bitmaps[1.0];
bmpTgt.SetSize(bmpSrc.Size);
bmpTgt.Assign(bmpSrc);

Upvotes: 0

markus_ja
markus_ja

Reputation: 2951

I found a solution but don't know if that is the prefered way.

var
  s: TSizeF;
begin
  s.Create(32, 32); //Image size
  myImage.Bitmap := myImageList.Bitmap(s,imageIndex);
end;

Upvotes: 5

Related Questions