D. Flo
D. Flo

Reputation: 81

TimageList does not contain a member named GetBitmap

I want to load pictures from an ImageList to a TImage (mobile application, fmx). The TImage is part of my customstyle Listbox (LBItem.StylesData['myimage']). The standard approach would be ImageList.GetBitmap(). However the GetBitmap method gives me an error: 'TimageList does not contain a member named GetBitmap'. Any explanation or alternatives? Thanks in advance!

procedure TForm3.Button1Click(Sender: TObject);
var
    i         : Integer;
    LBItem    : TListBoxItem;
    Bitmap : TBitMap;
begin
    ListBox1.BeginUpdate;
    ListBox1.Items.Clear;
    Bitmap := TBitMap.Create;
    try
        for i := 0 to 3 do begin
            LBItem := TListBoxItem.Create(nil);
            LBItem.Parent := ListBox1;
            LBItem.StyleLookup := 'mystyle';
            LBItem.StylesData['mylabel'] := 'Some text...';
            //Bitmap.LoadFromFile('D:\Koala.jpg');
            ImageList1.GetBitmap(i, Bitmap);
            LBItem.StylesData['myimage']:= Bitmap;
        end;
    finally
        ListBox1.EndUpdate;
    end;
end;

Upvotes: 3

Views: 3382

Answers (3)

Dreamer64
Dreamer64

Reputation: 1189

In FMX you don't need any additional coding for that, just use TGlyph instead of TImage if you want to display images directly form ImageList.

example :

Glyph1.ImageIndex := i;

Upvotes: 2

StanE
StanE

Reputation: 2783

Assuming you have an TImage with name Image1, a TImageList with name ImageList1 and at least one entry in the list with image for scale 1.0 called Image1Hover, then you can use the following example to load a "hover picture" in the OnEnter event of Image1:

procedure TForm1.Image1MouseEnter(Sender: TObject);
var
  Item: TCustomBitmapItem;
  Size: TSize;
begin
  ImageList1.BitmapItemByName('Image1Hover', Item, Size);
  Image1.Bitmap := Item.MultiResBitmap.Bitmaps[1.0];
end;

Upvotes: 6

kami
kami

Reputation: 1458

This answer is translate from fire-monkey.ru

Use ImageList1.Bitmap(Size, Index);. The size is in physical pixels, i.e. we consider the scale independently (this method knows nothing about the scale of the canvas). This function selects the most appropriate size of the image that is available.

So, your code should look something like this:

LBItem.StylesData['myimage'] := ImageList1.Bitmap(
  TSizeF.Create(myImageWidth * Canvas.Scale, myImageHeight * Canvas.Scale), 
  i);
// Not sure of the correctness of this assignment to 'myimage'

Note 1 All the bitmaps obtained in the 'ImageList1.Bitmap` are stored in the imagelist cache. So don't release them.

Note 2 ListBox has internal mechanism to interact with ImageList. Try to use icon: TImage style item and LBItem.ImageIndex property, without load bitmaps.

Upvotes: 3

Related Questions