"参数无效&QUOT。节约使用位图时, [英] "Parameter is not valid." when using saving bitmap
本文介绍了"参数无效&QUOT。节约使用位图时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
喜
我试着去拯救一个位图JPG格式带有指定的编码质量。然而调用保存方法时即时得到一个异常(参数是无效的。)。
Hi 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 +是pretty片状。你需要使用16L的值或投地(长)。
GDI+ is pretty flaky. You'll need to use 16L for the value or cast to (long).
这篇关于&QUOT;参数无效&QUOT。节约使用位图时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文