13,825
社区成员
发帖
与我相关
我的任务
分享
void __fastcall CrnAddTImageToImageList(TImage *img, TImageList *il)
{
Graphics::TBitmap *bmp = new Graphics::TBitmap;
bmp->Width = 30;
bmp->Height = 30;
bmp->Canvas->StretchDraw(TRect(0, 0, 30, 30), img->Picture->Graphic);
il->Add(bmp, NULL);
delete bmp;
}
// ---------------------------------------------------------------------------
//
void __fastcall TForm1::Button1Click(TObject *Sender)
{
CrnAddTImageToImageList(Image1, ImageList1);
}
void __fastcall CrnAddTImageToImageList(TImage *img, TImageList *il)
{
if (img->Picture->Graphic->InheritsFrom(__classid(Graphics::TBitmap)))
il->Add(img->Picture->Bitmap, NULL);
else if (img->Picture->Graphic->InheritsFrom(__classid(TIcon)))
il->AddIcon(img->Picture->Icon);
else if (img->Picture->Graphic->InheritsFrom(__classid(TJPEGImage)))
{
Graphics::TBitmap *bmp = new Graphics::TBitmap;
bmp->Width = img->Picture->Width;
bmp->Height = img->Picture->Height;
bmp->Assign(img->Picture->Graphic);
il->Add(bmp, NULL);
delete bmp;
}
}
// ---------------------------------------------------------------------------
//
void __fastcall TForm1::Button1Click(TObject *Sender)
{
CrnAddTImageToImageList(Image1, ImageList1);
}
// 添加到最后:
ImageList1->Add(Image1->Picture->Bitmap, NULL);
// 添加到i后面:
ImageList1->Insert(i, Image1->Picture->Bitmap, NULL);