I have a TcpListener
which gets an endless stream of byte array
. From that, I convert the byte() to MemoryStream and feed a PictureBox to display the images. That works fine.
If I set the anchor points on the PictureBox to top/right/bottom/left
which means the image will expand when the form expands and then I actually expand the form, I get the following error:
An unhandled exception of type 'System.ArgumentException' occurred in System.Drawing.dll
Additional information: Parameter is not valid.
Also,
The application is in break mode
Code
' Enter the listening loop.
While True
Dim client As TcpClient = Await server.AcceptTcpClientAsync()
Dim stream As NetworkStream = client.GetStream
Dim MS As New MemoryStream
Await stream.CopyToAsync(MS)
Await ViewImage(MS)
client.Close()
End While
View image function:
Public Async Function ViewImage(ms As MemoryStream) As Task
Try
Dim myimage As Bitmap
myimage = New Bitmap(ms)
PictureBox1.Image = myimage
PictureBox1.Refresh()
myimage.Dispose()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Function
Please note that the exception is not caught within my code. Any ideas?