Vb, Delphi, .net, framework, C++, Java, Pascal,Visual Studio, Asm, Ruby, C#, j#, Cs, Html, Php, Perl, Asp, xHtml Get Free Souce Code Here...

Inserting a .bmp file into your .exe

This is helpful if you do not want to have a bitmap file in the directory of the program you distribute.

One problem with inserting a bitmap file into your .exe is that it makes your programs .exe larger, so it is a good idea if your
program uses small bitmap files.
The Delphi example below will work on any version of Delphi above Delphi 2.

First open an editor like Notepad.exe, for this example we will use a bitmap file called Picture.bmp
and this is the bitmap file we will insert into our programs .exe
(Make sure that there is a picture in your folder/directory named Picture.bmp.
If you do not have a picture already called Picture.bmp you can rename a different bitmap file so that it is called Picture.bmp)

Type these words into the text file:

ThePicture Bitmap "Picture.bmp"

Then save the text file as:


We will use BRCC32.exe that comes with Delphi and it should be in Delphi's Bin directory, to compile the file.
In order to use BRCC32.exe you have to use a DOS window, using DOS is not hard at all.
To run a DOS window, go to your TaskBar, click Start|Programs|MS-DOS Prompt
Whenever you use DOS all you have to do to get back to Windows (Your desktop) is type the word Exit, then press the Enter

You should have your bitmap files and your .rc file in the same folder/directory.

So we will type this sentence in the DOS window:
C:\Delphi 3\Bin\Brcc32.exe C:\Delphi 3\bin\bmps\MyBmp.rc
The above paths may have to be changed to the place where you have Delphi installed and to the folder/directory where you
have saved your files for this example.

If this does not work or you get an error, you may not have Delphi in your computers path.
A way around this is for you to copy the BRCC32.exe and RW32CORE.DLL into your folder/directory that you are using,
then try again.
(The above files, BRCC32.exe and RW32CORE.DLL, may be different for different versions of  Delphi)

Use Explorer or another File Manager and have a look in your directory, you should find that you have an extra file called

Start Delphi, then start a new project (Application).

Look for {$R *.DFM} in Unit1 and add {$R MYBMP.RES} next to it.

Add a TImage component to your form and make its AutoSize property True.
Next drop a Button onto your Form, double-click on the Button and add this code:

Image1.Picture.Bitmap.LoadFromResourceName(hInstance, 'ThePicture');

Note we use 'ThePicture' to call the bitmap file.
Run the program and then click on the Button, you should see the image that you put into the resource file.
If you have to save the project before you can run it, save in in the same folder/directory where you have the resource (*.RES)

Your complete unit should look like this:

unit Unit1;


uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

  TForm1 = class(TForm)
    Button1: TButton;
    Image1: TImage;
    procedure Button1Click(Sender: TObject);
    { Private declarations }
    { Public declarations }

  Form1: TForm1;



procedure TForm1.Button1Click(Sender: TObject);
  Image1.Picture.Bitmap.LoadFromResourceName(hInstance, 'THEPICTURE');



Post a Comment