I pass an array to a method and I use a foreach loop. The parameter I'm passing to new Bitmap() is not valid for some reason. I get the error "Parameter is not valid." The parameter is a string path (as it should be).
Can anyone tell me what's wrong?
If I highlight the parameter name, this is what it shows me, which seems to be correct:
"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);
}
}
(根据以上问题的评论:这是一个简单的FileNotFound
错误。)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.