Board index » delphi » simple Q : load bitmap resource file

simple Q : load bitmap resource file

Sorry to ask such a simple question but I fail to do this myself.

I wanna load a bitmap named 'BITMAP_A' in SIMPLE.RES. I created it in
Image Editor of D2, as new .RES file,  and the bitmap should be under
the tree of Contents, Bitmap.

I use the following code to load the bitmap and display it in the
form.

(* -------------------------------------------- *)
implementation

{$R SIMPLE.RES}
{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
   WordBMP : TBitMap;
begin
  WordBMP := TBitMap.Create;
  WordBMP.LoadFromResourceName(Handle,  'BITMAP_A');
  Form1.Canvas.Draw(1, 1, WordBMP);
end;

(* -------------------------------------------- *)

I don't know what to fill in with the resource name in
LoadFromResoureName method but guessing. Please direct to the info
about this since the HELP file does not _help_ much.

Stephen Tse
steph...@hknet.com

 

Re:simple Q : load bitmap resource file


Quote
Stephen Tse (steph...@hknet.com) wrote:

 >> Sorry to ask such a simple question but I fail to do this myself.

 >> I wanna load a bitmap named 'BITMAP_A' in SIMPLE.RES. I created it in
 >> Image Editor of D2, as new .RES file,  and the bitmap should be under
 >> the tree of Contents, Bitmap.

 >> I use the following code to load the bitmap and display it in the
 >> form.

 >> (* -------------------------------------------- *)
 >> implementation

 >> {$R SIMPLE.RES}
 >> {$R *.DFM}

 >> procedure TForm1.Button1Click(Sender: TObject);
 >> var
 >>    WordBMP : TBitMap;
 >> begin
 >>   WordBMP := TBitMap.Create;
 >>   WordBMP.LoadFromResourceName(Handle,  'BITMAP_A');
 >>   Form1.Canvas.Draw(1, 1, WordBMP);
 >> end;

 >> (* -------------------------------------------- *)

 >> I don't know what to fill in with the resource name in
 >> LoadFromResoureName method but guessing. Please direct to the info
 >> about this since the HELP file does not _help_ much.

 >> Stephen Tse
 >> steph...@hknet.com

I think you should use HINSTANCE a not HANDLE to lad a bitmat from resource.
Regards
Jerzy
 --------------------------------------------------------------
| Centrum Komputerowe VADIM                                    |
| ul. Kupiecka 28                                              |
| Zielona Gora 65-426 POLAND                                   |
| tel/fax:(+68)26-56-72;(+68)27-07-05; POLPAK(X.121) 16859013  |
| e-mail: va...@elmo.nask.waw.pl                               |
| from: Jerzy A.Radzimowski                                    |
 --------------------------------------------------------------

Re:simple Q : load bitmap resource file


On 23 Jun 1996 18:08:25 GMT, va...@elmo.nask.waw.pl (Centrum

Quote
Komputerowe VADIM) wrote:
>Stephen Tse (steph...@hknet.com) wrote:

> >> Sorry to ask such a simple question but I fail to do this myself.

> >> I wanna load a bitmap named 'BITMAP_A' in SIMPLE.RES. I created it in
> >> Image Editor of D2, as new .RES file,  and the bitmap should be under
> >> the tree of Contents, Bitmap.

> >> I use the following code to load the bitmap and display it in the
> >> form.

> >> (* -------------------------------------------- *)
> >> implementation

> >> {$R SIMPLE.RES}
> >> {$R *.DFM}

> >> procedure TForm1.Button1Click(Sender: TObject);
> >> var
> >>    WordBMP : TBitMap;
> >> begin
> >>   WordBMP := TBitMap.Create;
> >>   WordBMP.LoadFromResourceName(Handle,  'BITMAP_A');
> >>   Form1.Canvas.Draw(1, 1, WordBMP);
> >> end;

> >> (* -------------------------------------------- *)

> >> I don't know what to fill in with the resource name in
> >> LoadFromResoureName method but guessing. Please direct to the info
> >> about this since the HELP file does not _help_ much.

> >> Stephen Tse
> >> steph...@hknet.com

>I think you should use HINSTANCE a not HANDLE to lad a bitmat from resource.

I am shocked with that simple answer. :>

BTW, I could not find the equivalent method in D1 TBitMap. What is the
simplest way to do the same job in D1?

Stephen Tse
steph...@hknet.com

Other Threads