danielzee Posted January 11, 2008 Posted January 11, 2008 (edited) 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 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() Edited January 11, 2008 by PlausiblyDamp Quote
Administrators PlausiblyDamp Posted January 12, 2008 Administrators Posted January 12, 2008 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
joe_pool_is Posted July 10, 2009 Posted July 10, 2009 Rats! I was really hoping this thread would answer a similar question I have. Looks like I'll have to actually post my question as a new thread, though. Quote Avoid Sears Home Improvement
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.