Moving a captured bitmap picture across a LAN nework in vb.net

danielzee

New member
Joined
Jan 11, 2008
Messages
1
i am a writing a program to captured a bitmap from one computer and send it to another computer on a LAN network
the problem is that i alway get a prefect first bitmap pic on the picturebox on the client computer but one that follows it will be distorted with the first images
i tried flushing nothing works


this the server code fragment

Code:
Public Sub CaptureImage()
Dim data As IDataObject
Dim bmap As Image

---copy the image to the clipboard---
SendMessage(hWnd, WM_CAP_EDIT_COPY, 0, 0)

---retrieve the image from clipboard and convert it 
 to the bitmap format
data = Clipboard.GetDataObject()
If data Is Nothing Then Exit Sub
If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
---convert the data into a Bitmap---
bmap = CType(data.GetData(GetType(System.Drawing.Bitmap)), Image)
---save the Bitmap into a memory stream---
bmap.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
---write the Bitmap from stream into a byte array---
Image = ms.GetBuffer


End If
End Sub

this the client code

Code:
Public Function ReceiveImage() As Boolean

Try
Dim counter As Integer = 0
Dim totalBytes As Integer = 0
Dim bytesRead As Integer = 0
Do
---read the incoming data---
bytesRead = nws.Read(data, 0, client.ReceiveBufferSize)
totalBytes += bytesRead
---write the byte() array into the memory stream---

s.Write(data, 0, bytesRead)
counter += 1
Loop Until totalBytes >= SIZEOFIMAGE
Loop Until totalBytes >= SIZEOFIMAGE

---display the image in the PictureBox control---

i += 1

Select Case i
Case 2
PictureBox2.Image = Image.FromStream(s)

End Select

PictureBox1.Image = Image.FromStream(s)
PictureBox1.Refresh()
nws.Flush()
s.Flush()
client.Close()
 
Last edited by a moderator:
Where on the client is the variable s declared and is it ever needed outside of this method?

If you declare the memory stream within this one method and create a new instance for each call it might solve the problem.
 
Rats! I was really hoping this thread would answer a similar question I have.

Looks like Ill have to actually post my question as a new thread, though.
 
Back
Top