“参数无效”。当使用保存位图时 [英] "Parameter is not valid." when using saving bitmap
本文介绍了“参数无效”。当使用保存位图时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图保存具有指定编码质量的位图jpg格式。但是,当调用save方法时,我收到异常(参数无效)。
Im trying to save a bitmap jpg format with a specified encoding quality. However im getting an exception ("Parameter is not valid.") when calling the save method.
如果我省略了bmp.save中的最后两个参数,它将工作
If i leave out the two last parameters in the bmp.save it works fine.
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;
}
}
谢谢
推荐答案
GDI +很漂亮。您将需要使用16L的值或转换(长)。
GDI+ is pretty flaky. You'll need to use 16L for the value or cast to (long).
这篇关于“参数无效”。当使用保存位图时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文