我将数组传递给方法,并使用foreach循环。我传递给新Bitmap()的参数由于某种原因无效。我收到错误“参数无效”。参数是一个字符串路径(应该是这样)。
谁能告诉我什么是错的?
如果我突出显示参数名称,这就是它向我显示的内容,这似乎是正确的:
“C:\ Reinstatement Image Transporter \ Image Processing \ NYH004402800_REINSTMT_0e2837ae.jpg”
public static void CompressPictures(string[] processingFiles)
{
string originalFileName = "";
foreach (string file in processingFiles)
{
//I'm getting the error right here:
Bitmap pic = new Bitmap(file);
ImageCodecInfo jgpEncoder = GetEncoder(ImageFormat.Jpeg);
Encoder myEncoder = Encoder.Quality;
EncoderParameters myEncoderParameters = new EncoderParameters(1);
EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 50L);
myEncoderParameter = new EncoderParameter(myEncoder, 0L);
myEncoderParameters.Param[0] = myEncoderParameter;
originalFileName = Path.GetFileNameWithoutExtension(file.Remove(file.Length - 1, 1));
pic.Save(AppVars.ProcessingPolicyImagesFolder + originalFileName, jgpEncoder, myEncoderParameters);
}
}
答案 0 :(得分:1)
(根据上述问题的评论:这是一个简单的FileNotFound
错误。)