Hello,
here is my code piece. I know it's ugly written, but the idea is that I recieve an image over TCP IP and try to display it in a picturebox.
I'm getting an ArgumentExcepti on thrown here and I can't seem to catch , although the code is surrounded with try-catch blocks.
The argument exception complains about an invalid parameter is beeing related to image width. At least thats all I can tell from the exception.
The function itself it beeing called at a regular interval using a Threading.Timer class.
EDIT:
did some debugging, the image get's transfered correctly. Saved it to disk and it displays correctly. So no idea where the problem is comming from.
here is my code piece. I know it's ugly written, but the idea is that I recieve an image over TCP IP and try to display it in a picturebox.
Code:
try
{
WriteMessage("Image Data recieved.");
int size = m_client.Available;
WriteMessage("Image Size: " + size.ToString() + " bytes.");
byte[] buffer = new byte[size];
nstream.Read(buffer, 0, size);
MemoryStream mstream = new MemoryStream();
mstream.Write(buffer, 0, size);
Image img = Image.FromStream(mstream);
m_display.Image = img;
img.Dispose();
mstream.Close();
// Ask next image.
WriteMessage("Asking next image.");
byte[] request = Encoding.ASCII.GetBytes(txt_message.Text);
if (nstream.CanWrite)
{
nstream.Write(request, 0, request.Length);
}
else
{
WriteMessage("Can't write next request.");
}
}
catch (Exception Ex)
{
WriteMessage(Ex.Message);
}
The argument exception complains about an invalid parameter is beeing related to image width. At least thats all I can tell from the exception.
The function itself it beeing called at a regular interval using a Threading.Timer class.
EDIT:
did some debugging, the image get's transfered correctly. Saved it to disk and it displays correctly. So no idea where the problem is comming from.
Comment