我将一个数组传递给一个方法,并使用一个 foreach 循环。由于某种原因,我传递给 new Bitmap() 的参数无效。我收到错误“参数无效”。该参数是一个字符串路径(应该是)。
谁能告诉我怎么了?
如果我突出显示参数名称,这就是它向我显示的内容,这似乎是正确的:
"C:\Reinstatement Image Transporter\Image Processing\NYH004402800_REINSMT_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);
}
}