Invalid parameter: Bitmap.Save ()

This is in an ASP.NET application.

Locally, this code works fine, but on our production server it throws an exception "Parameter is invalid" when calling Bitmap.Save ().

Should I use System.Drawing.Bitmap because its not recommended based on this:

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

Classes in the System.Drawing namespace are not supported for use in a Windows service or ASP.NET. Attempting to use these classes from in one of these types of applications can create unexpected problems, such as poor service performance and runtime exceptions.

What else can 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); 
+1
source share
3 answers

My best guess is that a Tiff codec is not installed on the server. If you use this in the Windows Server kernel, GDI + is not available.

+1
source

I would check the input stream you are passing. I would also like to make sure that I have relative paths mapped appropriately to the server paths.

0
source

I know that this may not be useful for everyone, as it may be feasible for some projects, and not for some others.

But the way I fixed this problem was to downgrade the target platform from version 3.5 to 2.0.

This is the only change I made, and then it worked. It looks like 3.5 is looking for another version of GDI + ...

Another thing I wanted to try was to use the patch from KB958911 , but I did not let it try, after changing the structure it worked for me.

Perhaps if you can’t lower the scope, you can try.

0
source

All Articles