【发布时间】:2011-03-22 20:38:22
【问题描述】:
这在 ASP.NET 应用程序中。
在本地,这段代码运行良好,但在我们的生产服务器上,当调用 Bitmap.Save() 时,它会抛出“参数无效”异常。
我应该不使用 System.Drawing.Bitmap,因为它不推荐基于此:
http://msdn.microsoft.com/en-us/library/system.drawing.aspx
不支持使用 System.Drawing 命名空间中的类 在 Windows 或 ASP.NET 服务中。 尝试使用这些类 在这些应用程序类型之一中 可能会产生意想不到的问题,例如 由于服务性能下降和 运行时异常。
我还能用什么?
Bitmap myBitmap = new Bitmap(img);
myBitmap.SetResolution(img.HorizontalResolution, img.VerticalResolution);
// get the tiff codec info
ImageCodecInfo myImageCodecInfo = GetEncoderInfo("image/tiff");
// Create an Encoder object based on the GUID for the Compression parameter category
System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Compression;
// create encode parameters
EncoderParameters myEncoderParameters = new EncoderParameters(1);
EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, (long)EncoderValue.CompressionCCITT4);
myEncoderParameters.Param[0] = myEncoderParameter;
// save as a tiff
myBitmap.Save(input, myImageCodecInfo, myEncoderParameters);
【问题讨论】:
-
你能说明一下
GetEncoderInfo(string)的功能吗? -
服务器缺少 tiff 编码器,但这还没有结束。就像 MSDN 文档所说的那样,System.Drawing 类不应该在服务中使用。我有一些第三方图像控件(Atalasoft),我用它来保存到 tiff。
标签: c# .net asp.net asp.net-4.0