Master Zero
Well-known member
- Joined
- Sep 10, 2005
- Messages
- 51
- Programming Experience
- Beginner
I am trying to send a large image through TCP sockets, but I seem to have hit a dead end. I am writing the network stream into a memory stream and from there I am try to create an image from that stream but I keep getting this exception:
Does anyone have a work around or solution?
The error happened when creating the BitMap from the memory stream:
I don’t understand what’s causing it or how to remedy it. I have search all over the net to no avail.A generic error occurred in GDI+.
Does anyone have a work around or solution?
VB.NET:
Private Sub AcceptData(ByVal ar As IAsyncResult)
'Dim client As Net.Sockets.TcpClient = CType(ar.AsyncState, Net.Sockets.TcpClient)
client.GetStream.EndRead(ar)
'If numOfBytesRead = 0 Then End
' Create a memory stream to hold the bytes
Dim mem As New IO.MemoryStream()
Do
mem.Write(buffer, 0, buffer.Length)
client.GetStream.Read(buffer, 0, buffer.Length)
Loop Until client.GetStream.DataAvailable = False
Dim img As New Bitmap(mem)
' Change the picture
UpdateImage(img)
client.GetStream.BeginRead(buffer, 0, client.ReceiveBufferSize, _
AddressOf AcceptData, client)
End Sub
The error happened when creating the BitMap from the memory stream:
VB.NET:
Dim img As New Bitmap(mem)