softtouch 9 Posted June 21, 2023 I have many images in a TImageCollection, all have different dimensions. because of the different dimensions, I cannot use a virtualimagelist with the collection, images would get scaled. I will draw the images manually when needed. Thats no problem, but how can I get the width and height of an image in the imagecollection? All the procedure/functions like GetBitmap etc. are all requesting a width and height and will scale the original image too. Share this post Link to post
Uwe Raabe 2057 Posted June 21, 2023 TImageCollection holds several Images, where each can have multiple sizes, which renders THE size of an image meaningless. You need to inspect the SourceImages of the Image returned by the collection to get the available sizes. Only if the image has just one SourceImage there also is only one size. Share this post Link to post
programmerdelphi2k 237 Posted June 21, 2023 @softtouch you can try some like this type TForm1 = class(TForm) ImageCollection1: TImageCollection; Memo1: TMemo; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} uses System.TypInfo; type ThelpToTWICImageFormat = record helper for TWICImageFormat function ToString: string; end; { ThelpToTWICImageFormat } function ThelpToTWICImageFormat.ToString: string; begin result := GetEnumName(typeinfo(TWICImageFormat), ord(self)).Remove(0, 3); end; procedure TForm1.Button1Click(Sender: TObject); var LICItem : TImageCollectionItem; LImage : TWICImage; LText : string; LImgCount: integer; begin LText := ''; LImgCount := ImageCollection1.Count; // for var i: integer := 0 to (LImgCount - 1) do begin LICItem := ImageCollection1.Images[i]; LText := LText + Format('Item (names): %s, sub-images: %d', [LICItem.Name, LICItem.SourceImages.Count]); // for var j: integer := 0 to LICItem.SourceImages.Count - 1 do begin LImage := LICItem.SourceImages.Items[j].Image; LText := LText + slinebreak + Format('....Sub-Image: %d W=%d, H=%d, format: %s', { } [j, LImage.Width, LImage.Height, LImage.ImageFormat.ToString]); end; // if (i < LImgCount) then LText := LText + slinebreak + slinebreak; end; // if LText.IsEmpty then LText := 'no images found'; // Memo1.Text := LText; end; end. Share this post Link to post
softtouch 9 Posted June 22, 2023 I already got what I need with the simple code: idx:=ImageCollection1.GetIndexByName(imagename); if idx<>-1 then begin var img:=ImageCollection1.Images[idx].SourceImages[0].Image; var x:=img.Width; var y:=img.Height; end; Share this post Link to post