RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TBitmap.Create Constructor

Instantiates a bitmap object.

Pascal
constructor Create; override;
C++
virtual __fastcall TBitmap();

Call Create to instantiate a bitmap object at runtime. Create is also called automatically when a bitmap image is loaded into a TImage. 

Create allocates memory for a bitmap object, and calls the inherited Create. Then it creates a TBitmapImage as the internal image that represents the bitmap.  

C++ Examples: 

 

/*
This example requires a resource file in the sources directory.
*/

#pragma resource "extrares.res"
#include <memory>       //for STL auto_ptr class

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  std::auto_ptr<Graphics::TBitmap> Bitmap1(new Graphics::TBitmap());
  try
  {
    Bitmap1->LoadFromResourceName((int)HInstance, "Live");
    Canvas->Draw(12,12,Bitmap1.get());
  }
  catch (...)
  {
    MessageBeep(0);
  }
}

 

Delphi Examples: 

{
This example demonstrates how to access a resource
file.  Specify the resource file with the $R directive
below. The RC file associated with the resource file
relates the resource name with the bitmap.
}

{$R extrares.res}

procedure TForm1.Button1Click(Sender: TObject);
var
 BitMap1 : TBitMap;
begin
  BitMap1 := TBitMap.Create;
  try
    BitMap1.LoadFromResourceName(HInstance,'Live');
    Canvas.Draw(12,12,BitMap1);
    BitMap1.LoadFromResourceName(HInstance,'Dead');
    Canvas.Draw(12,102,BitMap1);
  finally
    BitMap1.Free;
  end;
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!