0

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);
            }
        }
4
  • 1
    What's the error you're getting? Commented Aug 17, 2012 at 18:46
  • 1
    What's the exception type being thrown? If it's a FileNotFoundException then the problem is pretty straightforward, but it could be the file format is not valid or supported. Commented Aug 17, 2012 at 18:49
  • ahhhhhhhh it was filenotfound!! DUH! i had a logic error. fixed it. thanks lee :) Commented Aug 17, 2012 at 18:50
  • On a side note, you're creating an unknown number if Bitmaps and not calling Dispose() on any of them. Wrap that declaration in a using statement. Commented Sep 3, 2012 at 6:11

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.