1

I find a solution for Loading Bitmap From Resource file on How to store images in FireMonkey? And I've tried to use it in my Firemonkey application, but it can't find Resource and raises an error "EresNotFound". My Resource .RC File Is Like This

Bitmap_1    BITMAP    "Test.bmp"

and my Code is

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;

I also found a solution on the question Delphi 2010: unable to find resource - EResNotFound. But it still doesn't find recource

Community
  • 1
  • 1
Fayyaz
  • 199
  • 2
  • 13
  • Have you read this article https://delphihaven.wordpress.com/2013/01/26/surviving-without-image-lists-in-fmx/ and followed all the steps from there? – RBA Dec 21 '16 at 07:38

1 Answers1

8

There are several issues in your code, you need to declare resource as RCDATA

Bitmap_1    RCDATA    "Test.bmp"

Also looks like you created VCL application and there is a typo in resource type name, it should be RT_RCDATA, working FireMonkey code looks like this

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;
EugeneK
  • 2,164
  • 1
  • 16
  • 21
  • Thank you very much. It work's properly. thanks a lot. – Fayyaz Dec 21 '16 at 11:13
  • @Fayyaz, please [accept](http://stackoverflow.com/help/someone-answers) this answer if it is the solution to your problem... – whosrdaddy Dec 21 '16 at 13:43
  • 1
    `BITMAP` is a valid [resource type](https://msdn.microsoft.com/en-us/library/windows/desktop/ms648009.aspx), you can use `RT_BITMAP` instead of `RT_RCDATA` when creating the `TResourceStream`. – Remy Lebeau Dec 21 '16 at 20:54