471,119 Members | 1,436 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,119 software developers and data experts.

Memorystream bitmap with tcpclient and sockets

I have a memorystream of a bitmap, I want to send this over the network to a
client app so it can receive the bitmap, I am dabbling with sockets and
tcpclient's and ahve got a connection going but any documents I am looking up
are not exactly what i am looking for and end up confusing me as I am not so
familiar with this area, any help or code snippets would be great.
thanks,
barry.
Nov 21 '05 #1
1 2378
Are you interested in this Webservice sample I once made?

Cor

\\\needs a picturebox and 4 buttons on a windowform
Dim ds As New DataSet
Private abyt() As Byte
Private fo As New OpenFileDialog
Private sf As New SaveFileDialog
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
'Reading a picture from disk and put it in a bytearray
If fo.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(fo.FileName, _
IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
abyt = br.ReadBytes(CInt(fs.Length))
br.Close()
'just to show the sample without a fileread error
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button2.Click
'writing a picture from a bytearray to disk
If sf.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(sf.FileName, _
IO.FileMode.CreateNew)
Dim bw As New IO.BinaryWriter(fs)
bw.Write(abyt)
bw.Close()
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button3.Click
'writing a bytearray to a webservice dataset
Dim ws As New localhost.DataBaseUpdate
ws.SetDataset(abyt)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button4.Click
'reading a picture from a webservice dataset
Dim ws As New localhost.DataBaseUpdate
abyt = ws.GetByte
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End Sub
End Class
////
\\\\Webservice
<WebMethod()> _
Public Function GetByte() As Byte()
Dim ds As New DataSet
ds.ReadXml("C:\wsblob.xml")
Return CType(ds.Tables(0).Rows(0)(0), Byte())
End Function
<WebMethod()> _
Public Sub SetDataset(ByVal abyte As Byte())
Dim ds As New DataSet
ds.Tables.Add(New DataTable("Photo"))
ds.Tables(0).Columns.Add(New DataColumn("Sample"))
ds.Tables(0).Columns(0).DataType = GetType(System.Byte())
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow)
ds.Tables(0).Rows(0)(0) = abyte
ds.WriteXml("C:\wsblob.xml", XmlWriteMode.WriteSchema)
End Sub
////
Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Daniel | last post: by
3 posts views Thread by Ricardo Quintanilla | last post: by
reply views Thread by Torsten Brasch | last post: by
4 posts views Thread by vbdotnetmania | last post: by
2 posts views Thread by Bruce D | last post: by
13 posts views Thread by Don | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.