使用资源文件:[3]Image 显示资源图片
操作方法
- 01
首先编辑 rc 文件如下(假定图片文件放在程序目录下的 img 文件夹下):bmp1 BITMAP img\bmpFile1.bmpbmp2 BITMAP img\bmpFile2.bmp或者:bmp1,BITMAP,img\bmpFile1.bmpbmp2,BITMAP,img\bmpFile2.bmp然后在窗体上添加一个 Image、两个 Button, 代码如下: unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls;type TForm1 = class(TForm) Image1: TImage; Button1: TButton; Button2: TButton;procedure Button1Click(Sender: TObject);procedure Button2Click(Sender: TObject);procedure FormCreate(Sender: TObject);end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);begin Image1.AutoSize := True;end;procedure TForm1.Button1Click(Sender: TObject);begin Image1.Picture.Bitmap.Handle := LoadBitmap(HInstance, 'bmp1');end;procedure TForm1.Button2Click(Sender: TObject);begin image1.Picture.Bitmap.LoadFromResourceName(HInstance, 'bmp2');end;end.