How to store images in FireMonkey?

谁说胖子不能爱 提交于 2019-11-28 14:33:11

To add images in FireMonkey (XE4)

Project -> Resources and Images

Then to access it:

procedure TForm1.Button1Click(Sender: TObject);
var
  InStream: TResourceStream;
begin
  InStream := TResourceStream.Create(HInstance, 'MyPng', RT_RCDATA);
  try
    Image1.Bitmap.LoadFromStream(InStream);
  finally
    InStream.Free;
  end;
end;

Thanks to Peter Vonča

Because there is no ImageList in Delphi Android you have to:

  1. Add your Images to your Project

    Project -> Resources and Images

  2. Delcare the Images in 'Resources and Images' as ResourceType RCDATA

  3. Add this procedure:

->

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

Then Load your Images with e.g.:

var i : nativeint;
begin
  i := 1;      
  load_image_from_resource(Image1, 'Bitmap_' + inttostr(i));
end;

from everywhere.

Add your images as a resource via Project > Resources and Images.

For people who are looking at this question now, since Delphi XE8 FireMonkey has TImageList component

Put a TPopupMenu on your form and add some Menu Items and assign TBitmap of each TMenuItem. Then you can access bitmaps with this expression:

PopupMenu1.Items[index].Bitmap

or

MenuItem1.Bitmap
MenuItem2.Bitmap
...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!