我想加载图片从ImageList到TImage (移动应用程序,fmx)。TImage是我的自定义样式列表框(LBItem.StylesData['myimage'])的一部分。标准方法是ImageList.GetBitmap()。然而,GetBitmap方法给了我一个错误:'TimageList does not contain a member named GetBitmap‘。有任何解释或替代方案吗?提前感谢!
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;发布于 2016-09-16 07:35:24
假设您有一个名为Image1的TImage、一个名为ImageList1的TImageList以及列表中至少一个名为Image1Hover的scale 1.0图像条目,那么您可以使用以下示例在Image1的OnEnter事件中加载一个“悬停图片
procedure TForm1.Image1MouseEnter(Sender: TObject);
var
Item: TCustomBitmapItem;
Size: TSize;
begin
ImageList1.BitmapItemByName('Image1Hover', Item, Size);
Image1.Bitmap := Item.MultiResBitmap.Bitmaps[1.0];
end;发布于 2016-03-18 04:30:29
这个答案是从fire-monkey.ru翻译过来的
使用ImageList1.Bitmap(Size, Index);。size是以物理像素为单位的,即我们独立地考虑比例(此方法对画布的比例一无所知)。此函数用于选择可用的最合适的图像大小。
因此,您的代码应该如下所示:
LBItem.StylesData['myimage'] := ImageList1.Bitmap(
TSizeF.Create(myImageWidth * Canvas.Scale, myImageHeight * Canvas.Scale),
i);
// Not sure of the correctness of this assignment to 'myimage'备注1在ImageList1.Bitmap`中获取的所有位图都存储在imagelist缓存中,所以不要释放它们。
Note2 ListBox具有与ImageList交互的内部机制。尝试使用icon: TImage样式项和LBItem.ImageIndex属性,而不加载位图。
发布于 2018-11-30 03:03:37
在FMX中,你不需要任何额外的编码,如果你想直接从ImageList中显示图像,只需要使用TGlyph而不是TImage。
示例:
Glyph1.ImageIndex := i;https://stackoverflow.com/questions/35971656
复制相似问题