Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   FMX Imagelist PNG zufügen (https://www.delphipraxis.net/212496-fmx-imagelist-png-zufuegen.html)

creehawk 18. Feb 2023 09:04

FMX Imagelist PNG zufügen
 
Moin Moin.

Wie aus VCL gewohnt möchte ich eine Ladung PNG's (432 Stück) in eine ImageList schrauben, wobei diese Imagelist in einer ListView dann die Bilder via ImageIndex anzeigen soll. Schön.

Ich habe keinen Dunst wie ich die Bilder programmatisch in FMX da reinbekomme. Zu Fuß geht ja, aber bei 432 Stück..... :wall:

creehawk

softtouch 18. Feb 2023 09:38

AW: FMX Imagelist PNG zufügen
 
Vielleicht nicht 100%, aber so in etwa.

Code:
var
  si: TCustomSourceItem;
  d: TCustomDestinationItem;
  layer: TLayer;
  i,w,h:integer;
  st: TMemorystream;
begin
// favicons is the name of the image list
// st is a memorystream holding the image
// imagepath is a stringlist holding the filenames of the images

  favicons.ClearCache;
  favicons.Source.Clear;
  favicons.Destination.Clear;

  st:=TMemoryStream.create;

  for i:=0 to imagepath.count-1 do
  begin
    st.LoadFromFile(imagepath[i]);
    st.position:=0;
    si:=favicons.Source.Add;
    si.Name := 'image'+i.ToString;
    si.MultiResBitmap.LoadItemFromStream(st,1);
    si.MultiResBitmap.TransparentColor := TColorRec.Fuchsia;
    si.MultiResBitmap.SizeKind := TSizeKind.Custom;
    si.MultiResBitmap.Width := 16;
    si.MultiResBitmap.Height := 16;
    w:=si.MultiResBitmap.Bitmaps[1].Width;
    h:=si.MultiResBitmap.Bitmaps[1].Height;
    d:=favicons.Destination.Add;
    Layer := d.Layers.Add;
    Layer.SourceRect.Rect := TRectF.Create(0, 0, W , H);
    Layer.Name := si.name;
// Note: The index of the just added image can be retrieved with d.index here, to set for example the imageindex property in a listview item
  end;

  st.free;

end;

mmw 18. Feb 2023 09:43

AW: FMX Imagelist PNG zufügen
 
Hallo,

https://www.delphipraxis.net/199146-...parameter.html

Gruß

creehawk 18. Feb 2023 14:04

AW: FMX Imagelist PNG zufügen
 
Prima. vielen Dank, dann wollen wir sehen ....

creehawk

creehawk 18. Feb 2023 14:54

AW: FMX Imagelist PNG zufügen
 
Jupp, klappt. Wobei es erstmal um das eigentliche Verständnis geht, ausgehend von der TImageCollection in VCL.

Jetzt hätte ich aber noch eine Frage: in besagter IMageCollection kann ich via GetIndexByName sehr einfach den Index der Grafik in der Collection bekommen. In den Properties zur FMX ImageList finde ich da nichts ....

creehawk

P.S. Ich muss ein kleines Programm nach FMX portieren, sonst verwende ich FMX nicht.

mmw 18. Feb 2023 15:40

AW: FMX Imagelist PNG zufügen
 
Hallo,
so sollte es funktionieren -

Delphi-Quellcode:
var
  myBitmap:TCustomBitmapitem;
  mysize:Tsize;
  indx:Integer;
begin

myBitmap:=TCustomBitmapitem.Create(nil);

 try
  ImageList1.BitmapItemByName('Image',myBitmap,mysize);
  indx:=mybitmap.Index;

 finally
  myBitmap.Free;
 end;
end;
Gruß

creehawk 18. Feb 2023 17:13

AW: FMX Imagelist PNG zufügen
 
Nee, er gibt nur immer eine 0 zurück.

Aber:

Delphi-Quellcode:
    Index := MainForm.ImageList.source.Indexof(Bild);
das geht anstandslos. Ha!

Danke dir trotzdem natürlich.

creehawk


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:59 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz