locked
Parameter is not valid Exception RRS feed

  • Question

  • hi.. i have this code..

     
    Code Snippet
     MemoryStream ms = new MemoryStream();
                            ms.Seek(7, 0);
                            //take frame as an image
                            // b is a bitmap
                            System.Drawing.Image img = b;
                            try
                            {
                                //save image on memory
                                img.Save(ms,          System.Drawing.Imaging.ImageFormat.Jpeg);
                                img.Dispose();
                            }
                            catch (Exception expp)
                            {
                             }


    at the img.save line.. i get an exception that says Parameter is not valid... source "System.Drawing"... no inner exception

    this code runs in a timer tick .. the interval is 120ms..

    any ideas why this happens!! and what i need to do to solve this!

    Thnx
    Tuesday, June 12, 2007 10:06 AM

Answers

  • You're disposing of the b in this method?  Where does b come from, is it a parameter?  Does this exception happen all the time, or only after the first tick?

     

    Seems to me you've disposed of an object that is used in the timer tick, it could be that Image.Save is checking to make sure the image isn't disposed when it tries to save...

    Tuesday, June 12, 2007 1:25 PM

All replies

  • Does it give you the parameter that is invalid?  Look at the call stack to get the method that caused the error.  The problem could lie just about anywhere.  I would lean toward either the fact that you don't have an encoder for JPEG or the encoder received something it didn't like.

     

    Michael Taylor - 6/12/07

    http://p3net.mvps.org

    Tuesday, June 12, 2007 1:01 PM
  • You're disposing of the b in this method?  Where does b come from, is it a parameter?  Does this exception happen all the time, or only after the first tick?

     

    Seems to me you've disposed of an object that is used in the timer tick, it could be that Image.Save is checking to make sure the image isn't disposed when it tries to save...

    Tuesday, June 12, 2007 1:25 PM
  • in situations like this one always try to debug your app and check if the content of all variables is really ok..
    Wednesday, June 13, 2007 1:08 AM