Imaging problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akshah
    New Member
    • Feb 2007
    • 8

    Imaging problem

    I m developing a remote surveillance system in C# which takes screenshots at 3 seconds and sends the image to the remote server.

    The problem is after 7 to 8 screenshots(som etimes on the very first), I get an exception at the server of
    Invalid parameter to MemoryStream

    I m loading the byte buffer into the memory stream obj.

    Thnx in advance 4 any help.
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Are you closing the stream each time and disposing of the image?

    Comment

    • Motoma
      Recognized Expert Specialist
      • Jan 2007
      • 3236

      #3
      Originally posted by akshah
      I m developing a remote surveillance system in C# which takes screenshots at 3 seconds and sends the image to the remote server.

      The problem is after 7 to 8 screenshots(som etimes on the very first), I get an exception at the server of
      Invalid parameter to MemoryStream

      I m loading the byte buffer into the memory stream obj.

      Thnx in advance 4 any help.
      Welcome to The Scripts.
      When the error occurs, what method are you calling? What are the objects you are passing to the MemoryStream object? Could we see the code where the error is occuring?

      Comment

      • akshah
        New Member
        • Feb 2007
        • 8

        #4
        Originally posted by Motoma
        Welcome to The Scripts.
        When the error occurs, what method are you calling? What are the objects you are passing to the MemoryStream object? Could we see the code where the error is occuring?
        Sending Code -- At client side
        public void Send()
        {
        Image img = Image.FromFile( @"C:\image.jpg" );
        MemoryStream ms = new MemoryStream();
        img.Save(ms, ImageFormat.Jpe g);
        byte[] buf2 = ms.GetBuffer();

        byte[] buf = new byte[(buf2.Length/2) + 1];
        for (int i = 0; i < buf2.Length; i++)
        {
        if (i % 2 == 0)
        {
        buf[i / 2] = buf2[i];
        }
        }

        udpClient.Send( buf, buf.Length,"loc alhost",8001);
        ms.Close();
        img.Dispose();
        }

        *************** *************** *************** *************** *************
        //Receiving Code -- At the server side
        public void Receive()
        {
        UdpClient udpClient = new UdpClient(8001) ;
        while (true)
        {
        IPEndPoint endPoint = new IPEndPoint(IPAd dress.Parse("12 7.0.0.1"), 8001);

        byte[] buf2 = udpClient.Recei ve(ref endPoint);

        byte[] buf = new byte[buf2.Length * 2];
        for (int i = 0; i < buf.Length; i+=2)
        {
        buf[i] = buf2[i/2];
        buf[i+1]=buf2[i/2];
        }
        //The ERROR occurs in the following line: Invalid parameter
        MemoryStream ms = new MemoryStream(bu f);
        Image img = Image.FromStrea m(ms);
        Invoke(new UpdatePicBoxDel egate(UpdatePic Box), new object[] { img });

        ms.Close();
        }
        }

        Comment

        • kenobewan
          Recognized Expert Specialist
          • Dec 2006
          • 4871

          #5
          Obviously, buf is the invalid parameter. I suggest writing buf value to see if it is valid. Then work backwards through a debugging procedure until the code works...

          Hope that this helps.

          Comment

          • Motoma
            Recognized Expert Specialist
            • Jan 2007
            • 3236

            #6
            Originally posted by kenobewan
            Obviously, buf is the invalid parameter. I suggest writing buf value to see if it is valid. Then work backwards through a debugging procedure until the code works...

            Hope that this helps.
            I concur.
            Perhaps enclose it in a try...catch section, and report the typeof buf as well as the values when it fails.

            Comment

            Working...