LoadFromFile (C++)
Description
This example uses a button on a form and creates two bitmaps dynamically. One bitmap is monochrome, which means all nonwhite colors become black. The bitmap file path is relative to the Debug directory. Note: For C++ Builder, capitalization matters for the file name and path.
Code
#include <memory>       //For STL auto_ptr class
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  std::auto_ptr<Graphics::TBitmap> Bitmap1(new Graphics::TBitmap());
  std::auto_ptr<Graphics::TBitmap> Bitmap2(new Graphics::TBitmap());
  try
  {
	Bitmap1->LoadFromFile("..\\FACTORY.BMP");
	Bitmap2->Assign(Bitmap1.get());     // Copy Bitmap1 into Bitmap2.
    Bitmap2->Dormant();           // Free up GDI resources.
    Bitmap2->FreeImage();         // Free up Memory.
	Canvas->Draw(20, 20, Bitmap2.get());  // Note that previous calls do not lose the image.
    Bitmap2->Monochrome = true;
	Canvas->Draw(80, 80, Bitmap2.get());
    Bitmap2->ReleaseHandle();       // This will actually lose the bitmap.
  }
  catch (...)
  {
    MessageBeep(0);
  }
}
Uses
- Vcl.Graphics.TBitmap.Assign ( fr | de | ja )
 - Vcl.Graphics.TBitmap.Dormant ( fr | de | ja )
 - Vcl.Graphics.TBitmap.FreeImage ( fr | de | ja )
 - Vcl.Graphics.TBitmap.Monochrome ( fr | de | ja )
 - Vcl.Graphics.TBitmap.ReleaseHandle ( fr | de | ja )
 - Vcl.Graphics.TGraphic.LoadFromFile ( fr | de | ja )