简体   繁体   English

如何在VB6中读取图像文件流的结尾

[英]How to read the end of image file stream in VB6

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. 它是通过TCP IP连接来完成的。 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. 编辑:这是image.txt文件包含的内容。

1
1575020 // file size header
424D36040C0000000000360400002800000000040000000300000100080000000000000000000000
--data--
--data--
020303030203010302010202030002030203020302020302030202030102
3BFB

Is there any other efficient way to handle this in VB6? 在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. 您需要同意一个完整的协议,该协议指定如何在TCP流上传递图像数据和图像数据长度。

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 . 您可以在#VB Wiki上找到更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM