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

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

Public Function ReceiveImage() As Boolean

Dim counter As Integer = 0
Dim totalBytes As Integer = 0
Dim bytesRead As Integer = 0
'---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)

Hi DanielZee,
Bmap images tend to be quite large, i.e. 640*480 image equals 900K bytes. Try reducing the image size to say 160*120 to see if the image is un-corrupted. Also for this reason it may be better to transfer Jpeg images instead of Bmap.

Best Regards


See here for freeware webcam programs (and Tutorials) written in plain old C http://uk.geocities.com/ecafin/index.html

This article has been dead for over six months. Start a new discussion instead.