Recent

Author Topic: Where is defined TPNGImage?  (Read 7999 times)

Edson

  • Hero Member
  • *****
  • Posts: 1302
Where is defined TPNGImage?
« on: February 08, 2017, 09:38:37 pm »
I've seen several examples using TPNGImage, but I don't know, in which unit it's defined in Lazarus. 
Does it need to install some extra package?

I need to load some PNG files into a TImageList.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Where is defined TPNGImage?
« Reply #1 on: February 08, 2017, 09:49:07 pm »
Just load them. PNG support is built into the ImageList. For processing of the PNG image there's the TPortableNetworGraphic in graphics.

Edson

  • Hero Member
  • *****
  • Posts: 1302
Re: Where is defined TPNGImage?
« Reply #2 on: February 08, 2017, 10:25:23 pm »
Some code please.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

Edson

  • Hero Member
  • *****
  • Posts: 1302
Re: Where is defined TPNGImage?
« Reply #3 on: February 08, 2017, 10:29:17 pm »
I'm using:

Code: Pascal  [Select][+][-]
  1. var
  2.   bmp: TBitmap;
  3.   pngbmp: TPortableNetworkGraphic;
  4. begin
  5.    pngbmp:=TPortableNetworkGraphic.Create;
  6.    pngbmp.LoadFromFile(imgArc);
  7.    bmp:=TBitmap.Create;
  8.    pngbmp.Assign(bmp);
  9.    Result:= imagList16.Add(bmp, nil);
  10.    bmp.Destroy;
  11.    pngbmp.Destroy;
  12. end;

But this seems not to work.

 
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Where is defined TPNGImage?
« Reply #4 on: February 08, 2017, 10:40:14 pm »
You did not say that you want to add images by code.

This works for me (based on the first few lines of the OnClick code of the Add button in the ImageListEditor):

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. const
  3.   fn = 'C:\lazarus-trunk_fpc300\images\actions\arrow_down.png';
  4. var
  5.   srcBmp: TBitmap;
  6.   Picture: TPicture;
  7. begin
  8.   Picture := TPicture.Create;
  9.   try
  10.     Picture.LoadFromFile(fn);
  11.     SrcBmp := TBitmap.Create;
  12.     SrcBmp.Assign(Picture.Graphic);
  13.     ImageList1.Add(SrcBmp, nil);
  14.     ListView1.Invalidate;                // hooked to the image list
  15.   finally
  16.     Picture.Free;
  17.   end;
  18. end;    

Edson

  • Hero Member
  • *****
  • Posts: 1302
Re: Where is defined TPNGImage?
« Reply #5 on: February 08, 2017, 10:48:14 pm »
You did not say that you want to add images by code.
Sorry. It was my fault. I was trying to use TPNGImage to do by code.

Thanks, by the code.

This works too:

Code: Pascal  [Select][+][-]
  1. var
  2.   pngbmp: TPortableNetworkGraphic;
  3. begin
  4.    pngbmp:=TPortableNetworkGraphic.Create;
  5.    pngbmp.LoadFromFile('myfile.png');
  6.    Result:= imagList16.Add(pngbmp, nil);
  7.    pngbmp.Destroy;
  8. end;
  9.  
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

 

TinyPortal © 2005-2018