ImageConvert(@"E:\素材\xx.png", @"E:\素材\xx.ico"); public static void ImageConvert(string imagePath,string outPath) { Image img = Image.FromFile(imagePath); var width = 32; var height = 32; Size size; if ((width == 1) && (height == 1)) { size = new Size(img.Width, img.Height); } else { size = new Size((int)width, (int)height); } Bitmap bitmap = new Bitmap(img, size); ImageFormat format = ImageFormat.Icon; using (FileStream fs = new FileStream(outPath, FileMode.Create)) { if (format == ImageFormat.Icon) { IntPtr hwd = bitmap.GetHicon(); Icon icon = Icon.FromHandle(hwd); icon.Save(fs); } else { bitmap.Save(fs, format); } } }
标签:fs,转换,img,c#,图片格式,height,new,Icon,size From: https://www.cnblogs.com/sugarwxx/p/18184949