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?
Asked
Active
Viewed 1.1k times
1

Sky
- 4,244
- 7
- 54
- 83

Edijs Kolesnikovičs
- 1,627
- 3
- 18
- 34
-
http://delphihaven.wordpress.com/2013/01/26/surviving-without-image-lists-in-fmx/ – David Heffernan Aug 25 '13 at 09:21
5 Answers
12
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

Edijs Kolesnikovičs
- 1,627
- 3
- 18
- 34
-
2I'm glad that you found my answer useful, usually the appropriate step would be to accept the answer that solved your problem. Regarding your answer, the question was not about how to access resources, it's best to stay on topic. – Peter Aug 25 '13 at 17:00
5
Because there is no ImageList in Delphi Android you have to:
Add your Images to your Project
Project -> Resources and Images
Delcare the Images in 'Resources and Images' as ResourceType RCDATA
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.

Ingo
- 5,239
- 1
- 30
- 24
3
Add your images as a resource via Project > Resources and Images
.

Peter
- 2,977
- 1
- 17
- 29
-
Aren't you meant to do this with styles, as per Chris Rolliston's article? – David Heffernan Aug 25 '13 at 18:10
-
@DavidHeffernan, the article by Chris is irellevant to this question. The article shows a possible FMX solution to the behavior that we usually expect from the Timagelist component when used with other controls that make use of it , such as changing image indexes to differentiate user interaction on Toolbar speedButtons (hot, pressed, focus...) etc... . Here, the only question is how to store images for later use. – Peter Aug 25 '13 at 18:59
-
That's a very short sighted view. Image lists are there to allow images to be shared. And in FMX, styles serve the purpose. – David Heffernan Aug 25 '13 at 19:03
-
Well yeah, I was simply summarizing what I think the article is about. This isn't a question about changing the appearance of a control so I still don't know why you think that article is important here. – Peter Aug 25 '13 at 19:08
-
The title of Chris' article is *How to survive without image lists in a FireMonkey project*. Seems pertinent here. Chris knows a lot about FMX. And it's very different from VCL. – David Heffernan Aug 25 '13 at 19:14
-
Why would you base the relevance of an article on it's title? I've read it, it's a good article , still irellevant to this question. – Peter Aug 25 '13 at 19:25
-
-
I'm suggesting that you cannot base your opinion on the title of an article. I'm not exactly sure why you keep drilling into this, if you are so positive that his article is relevant to this question then my suggestion would be to post an answer explaining why that article is relevant. – Peter Aug 25 '13 at 20:12
-
Your answer is a very concise and literal response to the question. Which was, "how do I store images in a program?" And so I give you +1 for that. However, nobody is interested in storing images per se. You only store images because you want to use them. And the complexity is in the use of the images. Clearly you should store the images as resources. In my VCL apps, I don't have any images in .dfm file image list persistence. Instead I store images in resources that are loaded at runtime into image list. Contd. – David Heffernan Aug 25 '13 at 20:20
-
That allows me to choose which size images I want to load into the image list. The reason I'm using image lists is that I want to have a shared repository for my images, because a single image can and will be used from multiple places. For example, many of my forms have a file open button with a corresponding, shared, image. To me, the interest here is how to replace the image list in FMX. There is no direct equivalent to TImageList in FMX. So how to you manage shared images at the app level rather than the resource level? That's what Chris explains. – David Heffernan Aug 25 '13 at 20:22
-
I agree with your summation of the article, you put it in much better words then I do, I agree about storing images as resources instead in dfm, what I disagree with is your comment about how nobody is interested in storing images per se, this question is valid, it might not be particularly difficult one to answer but other people with such bad habbits will eventually stumble into the same issue as the author of this question. SO rules clearly state that questions and answers should be on topic, that article as correct as it might be just isn't relevant to this question. – Peter Aug 25 '13 at 20:40
1
For people who are looking at this question now, since Delphi XE8 FireMonkey has TImageList component

EugeneK
- 2,164
- 1
- 16
- 21
0
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
...

mh taqia
- 3,506
- 1
- 24
- 35
-
1Who said anything about popup menu? And are you sure you answer relates to FMX? – David Heffernan Aug 25 '13 at 10:08
-
1The goal is to store images in resource. when you assign image to Bitmap property of TMenuItem, the bitmap be stored in resource of executable. It is more accessible from resource. What should be done in the absence of ImageList? Be creative. – mh taqia Aug 25 '13 at 12:22