从VB转换为C#:bitmap.save()参数错误

时间:2014-06-03 22:33:14

标签: c# bitmap save

我正在将一段代码转换为c#,并且由于参数无效而在bitmap.save()处收到错误。转换后的代码是:

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);

关于为什么这种方法失败的任何想法?

1 个答案:

答案 0 :(得分:0)

质量需要很长的价值才能改变:

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

要:

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