Lazarus

Programming => Graphics and Multimedia => Graphics => Topic started by: AsleyCruz on March 12, 2020, 04:35:01 am

Title: SOLVED: Problem converting Png file to Ico
Post by: AsleyCruz on March 12, 2020, 04:35:01 am
Hi team,
I don't know to much about this but I am having problem
with this code. I want to convert a PNG file to ico
and save it to ico file. Please help me solve this.

Many thanks team.

Code: Pascal  [Select][+][-]
  1. var
  2.   vIcon: TIcon;
  3.   vPNG: TPortableNetworkGraphic;
  4. begin
  5.   vPNG := TPortableNetworkGraphic.Create;
  6.   vIcon := TIcon.Create;
  7.   try
  8.     vPNG.LoadFromFile('C:\Users\UserName\Desktop\information.png');
  9.     vIcon.Assign(vPNG);
  10.     vIcon.SaveToFile('C:\Users\UserName\Desktop\myIcon.ico');          
  11.   finally
  12.     vPNG.Free;
  13.     vIcon.Free;
  14.   end;
  15. end;

Error:
Cannot assign a TPortableNetworkGraphic to a TIcon.
Title: Re: Problem converting Png file to Ico
Post by: avk on March 12, 2020, 05:28:56 am
This works for me:
Code: Pascal  [Select][+][-]
  1. ...
  2. begin
  3.   with TPicture.Create do
  4.     try
  5.       LoadFromFile('Png1.png');
  6.       Icon.SaveToFile('icon1.ico');
  7.     finally
  8.       Free;
  9.     end;  
  10. end;
  11.  
Title: Re: Problem converting Png file to Ico
Post by: AsleyCruz on March 12, 2020, 06:22:19 am
This works for me:
Code: Pascal  [Select][+][-]
  1. ...
  2. begin
  3.   with TPicture.Create do
  4.     try
  5.       LoadFromFile('Png1.png');
  6.       Icon.SaveToFile('icon1.ico');
  7.     finally
  8.       Free;
  9.     end;  
  10. end;
  11.  

Thanks avk, it worked
And if I wanted to save that png to stream (not a file) , what would be the change?
Title: Re: Problem converting Png file to Ico
Post by: GAN on March 12, 2020, 06:28:13 am
https://lazarus-ccr.sourceforge.io/docs/lcl/graphics/tpicture.html (https://lazarus-ccr.sourceforge.io/docs/lcl/graphics/tpicture.html)

SaveToStream does not work?
TinyPortal © 2005-2018