[英]“Parameter is not valid.” when using saving bitmap
Im trying to save a bitmap jpg format with a specified encoding quality. 我试图保存具有指定编码质量的位图jpg格式。 However im getting an exception ("Parameter is not valid.") when calling the save method.
但是,在调用save方法时,我得到一个异常(“参数无效。”)。
If i leave out the two last parameters in the bmp.save it works fine. 如果我省略了bmp.save中的最后两个参数,它可以正常工作。
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;
}
}
Thank you 谢谢
GDI+ is pretty flaky. GDI +非常不稳定。 You'll need to use 16L for the value or cast to (long).
您需要使用16L作为值或转换为(long)。
您应该将质量值转换为long,如下所示:
eps.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)16);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.