如何在VB6中读取图像文件流的末尾 [英] How to read the end of image file stream in VB6

查看:61
本文介绍了如何在VB6中读取图像文件流的末尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有另一位我想改进的程序员编写的代码.该模块的目的是从摄像机获取实时图像流并将其显示在图片窗口中.它是通过TCP IP连接来完成的.这是完成的方式获取

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.

这就是image.txt文件包含的内容.

This is what the image.txt file contains.

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

在VB6中还有其他有效的方法来处理此问题吗?

Is there any other efficient way to handle this in VB6?

推荐答案

您需要同意一个完整的协议,该协议指定如何在TCP流上传递图像数据和图像数据长度.

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.

您可以在 #VB Wiki 中找到更多信息.

You can find a bit more info on the #VB wiki.

这篇关于如何在VB6中读取图像文件流的末尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆