引用空间:
using System.Drawing;
using System.IO;
核心代码:
string FileName = "D://img//01.jpg";//图片位置
Size size = new Size(40, 40);//设置要转换后的大小
//获得原始图片文件
using (Bitmap bm = new Bitmap(FileName))
{
using (Bitmap iconBm = new Bitmap(bm, size))
{
using (Icon icon = Icon.FromHandle(iconBm.GetHicon()))
{
string Name_ = "D://img//" + DateTime.Now.Ticks.ToString() + ".ico";
using (Stream stream = new System.IO.FileStream(Name_, System.IO.FileMode.Create))
{
icon.Save(stream);
}
}
}
}