我正在尝试使用以下代码在 Web 服务器上将图标转换为 png。但是在保存位图时,我总是收到“GDI+ 通用错误”。我错过了什么?
private static byte[] IconAsSizedPng(byte[] iconBytes, int iSize)
{
System.Drawing.Icon icon;
using(var ms = new System.IO.MemoryStream(iconBytes))
icon = new System.Drawing.Icon(ms, iSize, iSize);
using(icon) {
using(var bmp = icon.ToBitmap()) {
//bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Png);
using(var ms = new System.IO.MemoryStream()) {
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
return ms.ToArray();
}
}
}
}
字节数据为:
System.IO.File.ReadAllBytes(filePath)