Edijs Kolesnikovičs
Edijs Kolesnikovičs

Reputation: 1695

How to store images in FireMonkey?

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?

Upvotes: 1

Views: 11834

Answers (5)

EugeneK
EugeneK

Reputation: 2224

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

Upvotes: 1

Ingo
Ingo

Reputation: 5381

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.

Upvotes: 5

Edijs Kolesnikovičs
Edijs Kolesnikovičs

Reputation: 1695

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

Upvotes: 12

Peter
Peter

Reputation: 2977

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

Upvotes: 3

mh taqia
mh taqia

Reputation: 3586

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

Upvotes: 0

Related Questions