如何从资源文件加载图像 bmp 并将其加载到 image1.Picture 中?我试过这个:
{$R resource.res}
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
BitMap1 : TBitMap;
begin
BitMap1 := TBitMap.Create;
try
BitMap1.LoadFromResourceName(HInstance,'down');
Image1.Picture(BitMap1);
finally
BitMap1.Free;
end;
end;
但不起作用。谢谢!
我创建了一个文件。rc:
DOWN BMP DOWN.BMP
我用 brcc32.exe 编译:
brcc32.exe resource.rc
我实现了资源:
{$R resource.res}
但找不到文件bmp。
它不起作用,总是一个错误,但是我发现了另一个代码:
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
Image1.Picture.Bitmap.Handle := LoadBitmap(hInstance, 'DOWN');
end;
但是当我点击图片时消失了,为什么?谢谢
这是代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, XPMan, ExtCtrls;
type
TForm1 = class(TForm)
XPManifest1: TXPManifest;
Image1: TImage;
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{$R RESOURCE.RES}
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
Image1.Picture.Bitmap.Handle := LoadBitmap(hInstance,'DOWN');
end;
end.