本文介绍了参数无效调用Bitmap.Save()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这在ASP.NET应用程序。

在当地,这code运行良好,但我们的生产服务器上,它抛出一个异常的参数无效时Bitmap.Save()被调用。

我应该不会使用System.Drawing.Bitmap,因为它不是在此基础上recommened:

http://msdn.microsoft.com/en-us/库/ system.drawing.aspx

还有什么,我可以用?

 位图MYBITMAP =新位图(IMG);
myBitmap.SetResolution(img.Horizo​​ntalResolution,img.VerticalResolution);

//得到TIFF codeC信息
图片codecInfo MYIMAGE codecInfo = GetEn coderInfo(图像/ TIFF);

//创建基于GUID的COM pression参数类别一间codeR对象
System.Drawing.Imaging.En codeR myEn codeR = System.Drawing.Imaging.En coder.Com pression;

//创建连接code参数
恩coderParameters myEn coderParameters =新恩coderParameters(1);
恩coderParameter myEn coderParameter =新恩coderParameter(myEn codeR,(长)恩coderValue.Com pressionCCITT4);
myEn coderParameters.Param [0] = myEn coderParameter;

//保存为TIFF
myBitmap.Save(输入,MYIMAGE codecInfo,myEn coderParameters);
 

解决方案

我最好的猜测是,该服务器没有安装TIFF codeC。如果您在Windows Server Core上运行此,GDI +是不可用的。

This in in an ASP.NET application.

Locally, this code runs fine, but on our production server, it throws an exception of 'Parameter is not valid' when Bitmap.Save() is called.

Should I not be using System.Drawing.Bitmap because its not recommened based on this:

http://msdn.microsoft.com/en-us/library/system.drawing.aspx

What else could I use?

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);
解决方案

My best guess is that the server does not have the tiff codec installed. If you are running this on Windows Server core, GDI+ is not available.

这篇关于参数无效调用Bitmap.Save()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 09:52