Recent

Author Topic: SOLVED: Problem converting Png file to Ico  (Read 413 times)

AsleyCruz

  • Jr. Member
  • **
  • Posts: 78
    • Graphic and apps designer
SOLVED: Problem converting Png file to Ico
« 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.
« Last Edit: March 13, 2020, 06:35:23 am by AsleyCruz »
AsleyCruz - Graphic and apps designer
-
http://www.asleycruz.com/

avk

  • Sr. Member
  • ****
  • Posts: 273
    • my self-education project
Re: Problem converting Png file to Ico
« Reply #1 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.  

AsleyCruz

  • Jr. Member
  • **
  • Posts: 78
    • Graphic and apps designer
Re: Problem converting Png file to Ico
« Reply #2 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?
AsleyCruz - Graphic and apps designer
-
http://www.asleycruz.com/

GAN

  • Sr. Member
  • ****
  • Posts: 290
Re: Problem converting Png file to Ico
« Reply #3 on: March 12, 2020, 06:28:13 am »
Lazarus 2.0.8 FPC 3.0.4 Linux Mint Mate 19.3
Zeos 7.2.6 - Sqlite 3.32.3

Foro Lazarus en español http://forum.lazarus.freepascal.org/index.php/board,73.0.html

 

TinyPortal © 2005-2018