2. This is how:
- Code: Select all
var B = TBitmap.Create;
ImgList.GetBitmap(0, B);
TestImg.Picture.Assign(B);
delete B;
Note that you will lose half-transprency because unlike TImageList, TBitmap does not support it. What you can do however is use TImageList.Draw to draw on the target canvas, while keeping the background intact.
Here's a code sample that draws on Canvas of a blue TBitmap and then assigns the bitmap to TImage just so that we can see the result:
- Code: Select all
var B = TBitmap.Create;
B.Width = 32;
B.Height = 32;
//paint bitmap blue
B.Canvas.Brush.Style = bsSolid;
B.Canvas.Brush.Color = clBlue;
B.Canvas.Pen.Color = clBlue;
B.Canvas.Rectangle(0, 0, 32, 32);
//use TImageList.Draw to draw the icon anywhere while keeping half-transparency
ImgList.Draw(B.Canvas, 0, 0, i, True);
//show our results on screen
TestImg.Picture.Assign(B);
delete B;
Update: use clBtnFace instead of clBlue for form's color.
A little note: please don't get carried away with the popup-menus, there's a reason that their popularity is vanishing, they have very poor discoverability. We used to right-click every part of the interface years ago because that's what we were trained to do, but nowadays it's different and everything should be buttons and navigation and visible widgets. There are still a lot of places where right-click makes a lot of sense (text editors, file explorers) but it shouldn't be the only option to get to the required action.