Programming C++Builder How to convert an icon to a bitmap in C++Builder
Notice: Undefined variable: relatedArticlesCount in /home/wwwroot/codeback.net/plugins/content/tags.php on line 149

This example show you how to convert a specified icon to a bitmap. Easy way follow me. Create a new project in c++builder enviroment, put an Image, a Button and an OpenDialog control on the Form1. Rename the button1 ConvertIcon2Bitmap, then add the following codes as its OnClick event handler.

void __fastcall TForm1::ConvertIcon2BitmapClick(TObject *Sender)

{
  OpenDialog1->DefaultExt = ".ICO";
  OpenDialog1->Filter = "icons (*.ico)|*.ICO";
  OpenDialog1->Options << ofOverwritePrompt << ofFileMustExist << ofHideReadOnly;
  if (OpenDialog1->Execute())
  {
    TIcon *pIcon = new TIcon();
    try
    {
      AnsiString szBitmap;
      pIcon->LoadFromFile(OpenDialog1->FileName);
      szBitmap = ChangeFileExt(OpenDialog1->FileName,".BMP");
      Image1->Width = pIcon->Width;
      Image1->Height = pIcon->Height;
      Image1->Canvas->Draw(0,0,pIcon);

      Image1->Picture->SaveToFile(szBitmap);
      ShowMessage(OpenDialog1->FileName + "has been saved to " + szBitmap);
    }
    __finally
    {
      delete pIcon;
    }
}

Run your project to see the result and good luck!


Add comment


Security code
Refresh

Programming - C++Builder