So I was trying to convert a Bitmap image to JPEG in code and I keep getting this error:
An unhandled exception of type 'System.ArgumentException' occurred in System.Drawing.dll
Additional information: Parameter is not valid.
Here is the related code. All the paths are correct and the EncoderParameter is not null, what else could be causing this?
ImageCodecInfo codecInfo = null;
foreach( ImageCodecInfo codec in ImageCodecInfo.GetImageEncoders())
{
if (codec.MimeType != "image/jpeg") { continue; }
codecInfo = codec;
break;
}
EncoderParameters encoderParameters = new EncoderParameters();
encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 85);
using (Bitmap bitmapToConvert = new Bitmap(filePathIn))
{
bitmapToConvert.Save(filePathOut, codecInfo, encoderParameters);
}