Reputation: 3226
I am relatively new to Visual Basic. Currently working on visual studio 2005. I have an application that sends text message to a client (on our domain) using TcpClient in Visual Basic. As far as text is concerned, I can send it with ease and the client receives it. However, I am intending to send pictures to the client and force them to save at a specific location. Any suggestions regarding how to do this in VB. Many Thanks
Upvotes: 0
Views: 2877
Reputation: 27342
Read the picture into a byte array, send the byte array and then save the byte array to file at the other end. Some (untested) sample code from this site to do the conversion:
Private Function BytesToImage(ByVal ImageBytes() As Byte) As Image
Dim imgNew As Image
Dim memImage As New System.IO.MemoryStream(ImageBytes)
imgNew = Image.FromStream(memImage)
Return imgNew
End Function
Private Function ImageToBytes(ByVal Image As Image) As Byte()
Dim memImage As New System.IO.MemoryStream
Dim bytImage() As Byte
Image.Save(memImage, Image.RawFormat)
bytImage = memImage.GetBuffer()
Return bytImage
End Function
Upvotes: 1