C# png转ico
以下是C#中将PNG文件转换为ICO格式的示例代码:
using System.Drawing;
using System.Drawing.Imaging;
public static void ConvertPngToIco(string pngFilePath, string icoFilePath)
{
using (var pngImage = Image.FromFile(pngFilePath))
{
using (var icoImage = pngImage.GetThumbnailImage(256, 256, null, IntPtr.Zero))
{
using (var stream = new System.IO.FileStream(icoFilePath, System.IO.FileMode.Create))
{
icoImage.Save(stream, ImageFormat.Icon);
}
}
}
}
该代码通过使用.NET的System.Drawing库来加载PNG图像,将其缩小为256x256尺寸的图像,然后将其保存为ICO格式。可以调用此方法来将PNG文件转换为ICO格式:
ConvertPngToIco("input.png", "output.ico");
``
原文地址: https://www.cveoy.top/t/topic/hgXz 著作权归作者所有。请勿转载和采集!