Recent

Author Topic: TImageList with png of different size  (Read 3603 times)

hy

  • Full Member
  • ***
  • Posts: 221
TImageList with png of different size
« on: August 31, 2016, 11:46:59 am »
Hi, is there a workaround for TImageLists when the Images have different sizes?
Thanks in advance
_____
***hy
OS: debian sid(64bit)  [fpc 3.20] Lazarus 2.0.12

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: TImageList with png of different size
« Reply #1 on: August 31, 2016, 01:21:28 pm »
No, just use more than one imagelist.

Thaddy

  • Hero Member
  • *****
  • Posts: 14390
  • Sensorship about opinions does not belong here.
Re: TImageList with png of different size
« Reply #2 on: August 31, 2016, 05:23:29 pm »
From code yes.
Code: Pascal  [Select][+][-]
  1. // this is delphi mode
  2. // add generics.collections to uses
  3. var ImageList:Tlist<Timage>;

You need to do some work over a normal Timagelist to actually use it, but here you go: a container that contains images of potentially different sizes.
 
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

hy

  • Full Member
  • ***
  • Posts: 221
Re: TImageList with png of different size
« Reply #3 on: September 01, 2016, 11:11:32 am »
Thanks,
Solution: just make an array of TBitMap
Code: [Select]
TAImgIcons        =  array[IT_NOICO..IT_BODEGA_ICO] of TBitmap;         {where IT_NOICO..IT_BODEGA_ICO] are indexes of an own type}
populate
Code: [Select]
      for tit := succ(IT_NOICO) to high(tICOType) do
      begin
         sFileName := exe_path + cas_DefaultIcoNames[tit]; //get filenames from another array

         if fileexist(sFileName) then
         begin
            Image := tPicture.create;
            Image.LoadFromFile(sFileName);
         
            Icon := TBitmap.Create;
            Icon.TransparentColor:=clWhite;
            Icon.Transparent:=true;

            Icon.Assign(Image.Graphic);

            _AimgIcons[tit] := Icon;

      end; ///if fileexists
   end;// for
display
Code: [Select]
deviceCanvas.Draw(pt.x,pt.y, _AimgIcons[tit]); //where devicecancvas is the canvas where I want to draw the icons and pt. is a tPOINT which is calculated in advance
...

It works with png-files which have transparency
_____
***hy
OS: debian sid(64bit)  [fpc 3.20] Lazarus 2.0.12

Thaddy

  • Hero Member
  • *****
  • Posts: 14390
  • Sensorship about opinions does not belong here.
Re: TImageList with png of different size
« Reply #4 on: September 01, 2016, 12:08:44 pm »
That code leaks memory, although it is an option.
I suggest something like:
Code: Pascal  [Select][+][-]
  1. uses generics.collections;
  2. var
  3.   ImageList := TObjectList<TPicture>;
  4. begin
  5.  Imagelist := TObjectList<TPicture>.Create;
  6.  ImageList.OwnsObjects := True;  // will free all TPicures automatically when destroyed.
  7.  

The rest of your code should work as you wrote: Assign to TBitmap and draw. You only need one TBitmap, probably.
« Last Edit: September 01, 2016, 12:10:57 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018