converting .PNG to .ICO in C/C#

杀马特。学长 韩版系。学妹 提交于 2020-01-10 11:34:36

问题


I want to convert .PNG files to .ICO files. I want to do it locally with out any internet dependency (so I can't use online tools like converttoico.com etc).

I found a wonderful tool called png2ico, but it has a restriction that it can only convert images of size 1X1 to 256X256. Although for now, I am modifying the PNG resolution (in C#) and compressing it to 256X256, and then using this tool to convert it to icon, but the image quality is not good at all.

Does any one know of any native library for doing this or any tool (free or paid) that can help me?

Thank you.


回答1:


You can use ImageMagick library that can convert png to ico , you can find imageMagick for .NET here : http://imagemagick.codeplex.com/ .

If you need a program to do that you can try with IrFanView in batch mode ...




回答2:


Probably a little bit late, but here´s some c# solution to this:

using (FileStream stream = File.OpenWrite(@"C:\temp\test.ico"))
{
    Bitmap bitmap = (Bitmap)Image.FromFile(@"c:\temp\test.png");
    Icon.FromHandle(bitmap.GetHicon()).Save(stream);
}



回答3:


ImageMagick is the most awesome CLI image manipulation utility ever made:

convert image.png image.ico

It's that easy, and it works with virtually every format you throw at it.

Also, it has APIs for a quite a few different languages (C#, if I remember correctly).



来源:https://stackoverflow.com/questions/8381455/converting-png-to-ico-in-c-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!