I was trying to develop a video chat p2p system by sending bitmap of the picturebox where the webcam performs. I want to send and make the client just prompted without having the client to save the file by opening savefiledialog of the bitmap i was sending.
The sending part was like first I copy the frame of the picturebox which showing the video cam, and saved it into memorystream as .bmp file like this:
ms = New MemoryStream()
Dim a As Image
a = Server1.copyFrame(Me.PictureBox1, New RectangleF(0, 0, _
Me.PictureBox1.Width, Me.PictureBox1.Height))
a.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
Dim arrImage As Byte() = ms.ToArray()
Server1.SendCam(arrImage)
In different class file
Public Sub SendCam(ByVal arrImage As Byte())
Server.BroadcastSendCam(arrImage, Contact.Cam)
End Sub
Public Sub SendCam(ByVal msgTag As Byte, ByVal arrImage As Byte()) ', ByVal flag As Boolean)
SyncLock client.GetStream
'Dim arrImage As Byte() = ms.GetBuffer()
Dim w As New BinaryWriter(client.GetStream)
w.Write(RequestTags.Cam)
w.Write(msgTag)
'Send the file data
w.Write(arrImage)
w.Flush()
End SyncLock
End Sub
On the receiver side which is the following code, this is to retrieve the bytes and store it again to memorystream.
Case RequestTags.Cam
SyncLock client.GetStream
r = New BinaryReader(client.GetStream)
client.GetStream.Read(readByte, 0, 1)
passThroughByte = readByte(0)
'next expect length of data (Int32)
nData = r.ReadInt32
lenData = nData
'now comes the data, save it in a memory stream
mStream = New MemoryStream
lData = client.GetStream.Read(readBuffer, 0, PACKET_SIZE)
mStream.Write(readBuffer, 0, lData)
'Continue the asynchronous read from the NetworkStream
Me.client.GetStream.BeginRead(readByte, 0, 1, AddressOf ReceiveOneByte, Nothing)
End SyncLock
'once all data has arrived, pass it on to the end user as a stream
RaiseEvent VideoReceived(Me, passThroughByte, mStream)
mStream.Dispose()
Private Sub Cam(ByVal ms As MemoryStream)
PictureBox2.Image = Image.FromStream(ms)
End Sub
I got error showing on the following:
Public Sub HandleCam(ByVal ms As MemoryStream)
'Here, you handle adding the text to a text box.
Me.Invoke(New NewFileDelegate(AddressOf Cam), ms) 'This line was highlighted when I get the error.
End Sub
Any help will be much appreciated.
Thanks.

New Topic/Question
Reply



MultiQuote








|