JJ.
JJ.

Reputation: 9970

Bitmap class parameter not valid

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);
            }
        }

Upvotes: 0

Views: 1166

Answers (1)

Quuxplusone
Quuxplusone

Reputation: 27350

(Per the comments on the question above: It was a simple FileNotFound error.)

Upvotes: 1

Related Questions