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);}}}