limelect 52 Posted October 16, 2019 Delphi 10.2.3 I had a problem. On my Vcl program i had ImageList with 250 bitmaps. When making the same project for Android (fmx) ImageList is not the same.To transfer all bitmaps to fmx ImageList i made this program. 1. Make a VCL project with a button. Close the project. 2. Make new>Multi-Device form. 3. place on it a button and ImageList. 4. Make sure both forms have different name. 5. Save and close. 7. Open Vcl project. 8. Add Fmx Form to the VCL project. 9. Disregard ERRORS !! 10. Add below program to fmx  uses Unit2;  procedure TForm1.Button1Click(Sender: TObject); var  FileStream: TFileStream;  MemStream: TMemoryStream;  w, h, scale, iPos: Integer;  btBitmap: tbitmap;  si: TCustomSourceItem;  d: TCustomDestinationItem;  Layer: TLayer; begin  for iPos := 0 to Form2.ImageList1.Count - 1 do  begin   btBitmap := tbitmap.create;   btBitmap.PixelFormat := pf32bit;   btBitmap.AlphaFormat := afIgnored;   Form2.ImageList1.GetBitmap(iPos, btBitmap);   MemStream := TMemoryStream.Create;   btBitmap.SaveToStream(MemStream);   si := ImageList1.Source.Add;   si.Name := 'Source' + inttostr(iPos);   scale := 1;   si.MultiResBitmap.LoadItemFromStream(MemStream, scale);   W := si.MultiResBitmap.Bitmaps[scale].Width; //Get width from scale   H := si.MultiResBitmap.Bitmaps[scale].Height; //Get height from scale   // Destination   d := ImageList1.Destination.Add;   Layer := d.Layers.Add;   Layer.SourceRect.Rect := TRectF.Create(0, 0, W, H); // Create rect W x H   Layer.Name := si.name;   MemStream.Free;   btBitmap.Free;  end;  MemStream := nil;  FileStream := TFileStream.Create('MyList.DAT', fmCreate);  try   MemStream := TMemoryStream.Create;   MemStream.WriteComponent(Form1);   MemStream.Position := 0;   ObjectBinaryToText(MemStream, FileStream);  finally   MemStream.Free;   FileStream.Free;  end; end;  11. On vcl add  uses Unit1;  procedure TForm2.Button1Click(Sender: TObject); begin   Form1.ShowModal; end;  12. Execute vcl. 13. Press button. Open fmx form. 14. Press fmx button. 15. MyList.DAT file is created which is realy   an fmx form with all bitmaps populated in   in fmx ImageList1. 16. To end rename MyList.DAT > Unit1.fmx so you end up with   Unit1.pas and unit1.fmx. 17. Close the project. 18. Open your FMX project. 19. Open UNIT1 in the project 20. Copy ImageList1 from unit1 to your project. I hop it will help some one . And happy coding. 1 Share this post Link to post
David Heffernan 2446 Posted October 16, 2019 Images should not be stored in dfm files. They should be held in their original format and linked as resources. 1 Share this post Link to post
limelect 52 Posted October 16, 2019 (edited) @David Heffernan You mite be right but in my case this is what i did.  I do no see the difference (and i mite be wrong ) between resources and dfm since the program behavior will not change. What is the added value in your case ? At the time when  i did the VCL project i was not thinking of FMX. Edited October 16, 2019 by limelect Share this post Link to post
David Heffernan 2446 Posted October 16, 2019 (edited) The value is that you have the images in a useful form, not trapped in some weirdo base16 dfm format. You have names for your images, and not just integer indices. Edited October 16, 2019 by David Heffernan 3 Share this post Link to post
limelect 52 Posted October 16, 2019 @David Heffernan Well i understand but in my case integer is what i use. I have 250 "bitmap flags" associated to 2 constant lists all arranged in order of bitmap against name against number. with integer it is very easy to get bitmap+name+number all at once. Share this post Link to post
David Heffernan 2446 Posted October 16, 2019 Maybe this is time to do it the right way? Given that you have to change. 2 Share this post Link to post