我在How to store images in FireMonkey?找到了从资源文件加载位图的解决方案我试图在我的Firemonkey应用程序中使用它,但它找不到资源并引发错误“EresNotFound”。 我的资源.RC文件就像这样
Bitmap_1 BITMAP "Test.bmp"
我的代码是
procedure Tform1.load_image_from_resource(var Im1: Timage; res_name: String);
var InStream: TResourceStream;
begin
InStream := TResourceStream.Create(HInstance, res_name,RC_RTDATA);
try
Im1.Picture.Bitmap.LoadFromStream(InStream);
finally
InStream.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Load_image_from_resource(Image1,'Bitmap_1');
end;
我还在问题Delphi 2010: unable to find resource - EResNotFound上找到了解决方案。 但它仍然没有找到资源
答案 0 :(得分:8)
您的代码中存在多个问题,您需要将资源声明为RCDATA
Bitmap_1 RCDATA "Test.bmp"
另外看起来你创建了VCL应用程序并且资源类型名称中有一个拼写错误,它应该是RT_RCDATA,工作FireMonkey代码看起来像这样
procedure Tform1.load_image_from_resource(var Im1: Timage; res_name: String);
var InStream: TResourceStream;
begin
InStream := TResourceStream.Create(HInstance, res_name, RT_RCDATA);
try
Im1.Bitmap.LoadFromStream(InStream);
finally
InStream.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Load_image_from_resource(Image1, 'Bitmap_1');
end;