There is a code written by another programmer which I want to improve. The purpose of the module is to get a live image stream from camera and to display it in the picture window. It is doing it over the TCP IP connection. Here is how it is done Get the
Private Sub DataArrival(ByVal bytes As Long)
Dim str As String
' check the socket for data
camera.GetData str
Dim str As String
While InStr(str, Terminator) <> 0
**Do some processing and put only the data in the variable str
str = Mid(str, index, 1000)
lImgSize = lImgSize + Len(str)
strImg = strImg + str
If lImageSize >= 1614414 Then
Dim fileno As Integer
fileno = FreeFile()
Open ".\Imagefile.txt" For Output As #intFileNo
Print #fileno , strImg
Close #fileno
End If
End Sub
I have an input image stream coming and converting it to string and I am calculating the size to check the end of the image to write it in to a file. But the hardcoded value does not guarantee the end of file always. Sometimes If the image size is little less than the size, my picture box is not update with a live image.
EDIT: This is what the image.txt file contains.
1
1575020 // file size header
424D36040C0000000000360400002800000000040000000300000100080000000000000000000000
--data--
--data--
020303030203010302010202030002030203020302020302030202030102
3BFB
Is there any other efficient way to handle this in VB6?
You need to agree a full protocol that specifies how you're going to pass the image data and the image data length over the TCP stream.
In your receiver, you then start reading the data into a buffer until you get enough data to contain your headers. At this point, you can parse out the data length and then continue reading data into your data buffer until you at least that amount of data. When you finally get all the data, you can decode and save out the image data then either close the stream (if it's a one off) or start form the beginning and parse out the file header.
You can find a bit more info on the #VB wiki .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.