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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Winsock to Picture

Status
Not open for further replies.

AdamVerellen

IS-IT--Management
Sep 20, 2002
39
CA
I know there are a few other posts regarding this. But so far I havn't been able to get it to work.
I am using a Vision System camera that when triggered sends out the image data via tcp (winsock) connection.
The first bunch of characters state info about the image.
maybe 120 characters into the string it states the size of the image, then comes the image data.
Any ideas on how to change the image data into an image?
So far I set up the data receive to get Ascii then I convert to binary. Is that the correct approach?

Thanks

Adam
 
Just figured it out.
I am posting below. It's still a touch messy, but works.
Any suggestions are greatly appreciated :)

Private Sub sckMachine_DataArrival(ByVal bytesTotal As Long)
Dim ThisPacket As String

sckMachine.GetData ThisPacket, vbString

temp2 = temp2 & ThisPacket
Debug.Print Len(temp2) & " " & Str(temp) 'show how big the file is for debugging

If Len(temp2) > 1024 And Len(temp2) < 2048 And temp = 0 Then
temp = Mid(temp2, 114, 7)
End If

If Len(temp2) = 121 + temp Then
temp3 = Mid(temp2, 122, temp)

strTempFile = "C:\temp.dat" 'MWin32API.GetTempFile("vbt")

intFile = FreeFile
'
'write downloaded data to the file
Open strTempFile For Binary As #intFile
Put #intFile, , temp3
Close #intFile
'
'load the file into a picture box
Set Picture1.Picture = LoadPicture(strTempFile)

End If

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top