How to store images in FireMonkey?

守給你的承諾、 提交于 2019-11-27 08:25:46

问题


In VCL I had ImageList to store images. In FireMonkey there is no ImageList control. How do I store images in FireMonkey for later use?


回答1:


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




回答2:


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.




回答3:


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




回答4:


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




回答5:


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
...


来源:https://stackoverflow.com/questions/18426914/how-to-store-images-in-firemonkey

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