Msgstr "Invalid parameter." when using bitmap preservation

I am trying to save a bitmap JPG format with a given encoding quality. However, im gets an exception ("The parameter is invalid.") When calling the save method.

If I leave the last two options in bmp.save, it works fine.

EncoderParameters eps = new EncoderParameters(1); eps.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 16); ImageCodecInfo ici = GetEncoderInfo("image/jpeg"); string outfile = outputpath + "\\" + fileaddition + sourcefile.Name; bmp.Save(outfile,ici,eps ); bmp.Dispose(); image.Dispose(); return true; } ImageCodecInfo GetEncoderInfo(string mimeType) { int j; ImageCodecInfo[] encoders; encoders = ImageCodecInfo.GetImageEncoders(); for (j = 0; j < encoders.Length; ++j) { if (encoders[j].MimeType == mimeType) return encoders[j]; } return null; } } 

thanks

+3
source share
2 answers

GDI + is pretty flaky. You will need to use the 16L value for the value or click (long).

+26
source

You must distinguish a qualitative value to a long one, for example:

 eps.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)16); 
+4
source

All Articles