Bitmap.Save Parameter is not valid

Dexters picture Dexters · Mar 1, 2013 · Viewed 9.4k times · Source

I'm using Bitmap.Save(location,coded,parameters)to save first frame of a tiff image: the encoding scheme used is Tiff format. I then use saveadd() and so on. Works like a charm on win 7 64 bit, but does not work on 32 bit or older windows versions.

After researching I found it might be due to tiff image encoding processed differently with ones before GDI+.

Is there a way to overcome this without any drastic changes?

Sources:

Parameter is not valid calling Bitmap.Save()

http://social.msdn.microsoft.com/Forums/fi-FI/netfxbcl/thread/1585c562-f7a9-4cfd-9674-6855ffaa8653

Answer

mustafa öztürk picture mustafa öztürk · Mar 1, 2013

You must use "long" for the quality parameter

EncoderParameters parametre = new EncoderParameters(1);
parametre.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (quality as long));

or

EncoderParameters parametre = new EncoderParameters(1);
parametre.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 90L);

or

long quality=90; //
EncoderParameters parametre = new EncoderParameters(1);
parametre.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);