RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TBitmap.LoadFromResourceName Method

Loads a bitmap resource into the bitmap object.

Pascal
procedure LoadFromResourceName(Instance: THandle; const ResName: String);
C++
__fastcall LoadFromResourceName(THandle Instance, const AnsiString ResName);

LoadFromResourceName loads the specified bitmap resource along with palette information from a module's executable file. 

Instance is the handle of the module that contains the resource. 

ResName is the name of the resource to load.

Note: Use this routine to load bitmaps from RES files instead of the LoadBitmap API. LoadBitmap does not support 256-color images.
 

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!