converting from VB to C#: bitmap.save() parameter error

86 Views Asked by At

I'm converting a piece of code to c#, and am getting an error at bitmap.save() due to an invalid parameter. The converted code is:

System.Drawing.Bitmap picture = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromFile(FilePath);
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(w1, h1);
System.Drawing.Graphics gr_dest = System.Drawing.Graphics.FromImage(bitmap);
gr_dest.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

gr_dest.DrawImage(picture, -x1, -y1, effective_width, effective_height);

System.IO.Stream output = new System.IO.MemoryStream();
System.Drawing.Imaging.EncoderParameters encoderParams = new System.Drawing.Imaging.EncoderParameters(1);
System.Drawing.Imaging.EncoderParameter encoderParam = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 96);
encoderParams.Param[0] = encoderParam;
System.Drawing.Imaging.ImageCodecInfo ici = GetEncoderInfo("image/jpeg");
bitmap.Save(output, ici, encoderParams);

Any ideas on why this method is failing?

1

There are 1 best solutions below

0
SKall On BEST ANSWER

Quality needs to be a long value so change:

(System.Drawing.Imaging.Encoder.Quality, 96)

To:

(System.Drawing.Imaging.Encoder.Quality, 96L)