GDI+ throws "Parameter is not valid" exception when calling Image.Save with Encoder.Transformation

Dec 28 2009 1:21 AM
Hi there.
I am trying to load and save a jpeg file losslessly, however I get an exception when I try to save the file.
The code bellow works fine, however, it will break if I replace the EncoderParameter with the one in the commended line.
Any help will be appreciated?

                       using (Image b = Image.FromFile("somefile.jpg"))
{

using (Graphics g = Graphics.FromImage(b))
{
g.DrawString("some text", new Font("Arial", 10), Brushes.Yellow, b.Size.Width, b.Size.Height);
String newName = "newfile.jpg";

ImageCodecInfo encoderInfo = GetEncoderInfo("image/jpeg");

EncoderParameters encParams = new EncoderParameters(1);
encParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L);
//encParams.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.Transformation,(long)EncoderValue.TransformRotate90);
b.Save(newName, encoderInfo, encParams);
}
}


Answers (3)