Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

winsock and pictures

Status
Not open for further replies.

EnCocytus

Programmer
Dec 18, 2002
24
US
I'm trying to figure out a way to send pictures (not necessarly files, but like an stdPicture) over a simple tcp winsock connection. I can't seem to find anything, neither code nor tutorials. I've searched the forums, and haven't found a direct answer to this question. I 've also looked at the work of SS Ahmed as suggested in another thread, from long ago, and that hasn't turned up anything. Anybody got some suggestions, links, or code I could look at?

Thanx

1001100 1110101 1101011 1100101
 

Does the source have to be A TCP/IP Server?? The easiest way is to use the OpenUrl method and store the pics on a website or webserver someplace.

Dim b() As Byte
Dim strURL As String
' Set the strURL to a valid address.
strURL = "FTP://ftp.GreatSite.com/me.gif"
b() = Inet1.OpenURL(strURL, icByteArray)

Open "C:\Temp\any.gif" For Binary Access _
Write As #1
Put #1, , b()
Close #1


If you have to have a 100% Tcp/Ip transfer you might do the same save format but use GetChunk method to get data from the other peer.

Hope this Helps,
J Stephens
 
An intersesting idea. I definitely need a 100% tcp/ip transfer. However, i never thought of recieving the data as a byte array, and trying to force it into a picture type. (An idea i got from reading your post). One quick question though, what is Inet1 declared as. It's not a winsock is it? Cause I don't recognize the methods.

Anyways, thanks for the help, and the flurry of new ideas. I'll let you knew if I figure it out.

1001100 1110101 1101011 1100101
 
does anyone know how to uploading picture to remote host or server?
 
You can use the fact that StdPicture knows how to persist itself to send any image that can be loaded through LoadPicture, or preloaded at design time into any control's Image or Picture property, directly via Winsock.

No forcing into a picture type from binary data, no intermediary files, tiny amount of code. Your first port of call would be to look at the PropertyBag object.
 
In fact, I'm such a fan of the technique that I'm going to post an illustrative example even though the original question is more than a month old. You'll need a form with two pictureboxes, two Winsock controls and a command button (the example works as both sender and receiver for the purposes of illustration). Picturebox1 should have it's Picture property set at design time (or add a LoadPicture command in the Form's Load event):
[tt]
Option Explicit

Private Sub Command1_Click()
Dim pb As PropertyBag

Set pb = New PropertyBag
pb.WriteProperty "SentStdPicture", Picture1.Picture, 0
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.Connect
' Wait for connection
Do Until Winsock1.State = sckConnected
DoEvents
Loop
Winsock1.SendData pb.Contents

End Sub

Private Sub Form_Load()
' Set up sender and receiver
Winsock1.RemoteHost = &quot;127.0.0.1&quot;
Winsock2.RemoteHost = &quot;127.0.0.1&quot;
Winsock1.RemotePort = 1001
Winsock2.LocalPort = 1001
Winsock2.Listen
End Sub

Private Sub winsock2_Close()
Winsock2.Listen
End Sub

Private Sub winsock2_ConnectionRequest(ByVal requestID As Long)
If Winsock2.State <> sckClosed Then Winsock2.Close
Winsock2.Accept requestID
End Sub

Private Sub winsock2_DataArrival(ByVal bytesTotal As Long)
Dim pb As PropertyBag
Dim buffer() As Byte

Set pb = New PropertyBag
Winsock2.GetData buffer, vbByte + vbArray, bytesTotal
pb.Contents = buffer
Set Picture2.Picture = pb.ReadProperty(&quot;SentStdPicture&quot;, 0)
End Sub
 
Oh well, clearly not of interest to anyone. You'll all regret it, you know...
 
strongm, don't be disheartened, it's suddenly become of great interest to me.

Unfortunately after trying your code I get the error &quot;Invalid use of New keyword&quot;.

I have looked up PropertyBag Object at MSDN but the Help isn't very helpful to me.

Can you help me at all?

Experience is something you don't get until just after you need it.
 
>Don't forget to add the components Winsock.

I already did (1 & 2)

I am using VB5 - could this be the problem?

Experience is something you don't get until just after you need it.
 
Thanks Frederico.

Does anybody else know if the PropertyBag is VB6 only?

Experience is something you don't get until just after you need it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top