检测JPG图像的Eof [英] Detect Eof for JPG images

查看:76
本文介绍了检测JPG图像的Eof的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过TCP从服务器到客户端连续不断地发送许多图像.现在,在客户端,我应该如何有效地检测到这是我的一个图像的结尾,因此将其记录在文件系统中,然后再记录下一个图像,依此类推.

I am sending many images from my server to client in sequence continuously through TCP.Now at client,how should i detect efficiently that this is end of my one image so write it down in file system and then next image and so on.

最诚挚的问候, ...

Best regards, ...

推荐答案

好吧,我们无法保证您不会在jpeg图像中找到FFD9.找到jpeg图像结尾的最好方法是解析它.除FFD0至FFD9和FF01(保留)外,每个标记都紧随其后的是一个长度说明符,它将为您提供该标记段的长度,包括长度说明符,但不包括标记. FF00不是标记,但是出于您的目的,您可以将其视为没有长度说明符的标记.

Well, there's no guarantee that you won't find FFD9 within a jpeg image. The best way you can find the end of a jpeg image is to parse it. Every marker, except for FFD0 to FFD9 and FF01(reserved), is immediately followed by a length specifier that will give you the length of that marker segment, including the length specifier but not the marker. FF00 is not a marker, but for your purposes you can treat it as marker without a length specifier.

长度说明符是两个字节长,是大字节序.因此,您要做的就是搜索FF,如果以下字节不是0x00、0x01或0xD0-0xD8之一,则您读取长度说明符,并在流中向前跳过,只要长度说明符表示减去两个字节即可.

The length specifier is two bytes long and it's big endian. So what you'll do is search for FF, and if the following byte is not one of 0x00, 0x01 or 0xD0-0xD8, you read the length specifier and skips forward in the stream as long as the length specifier says minus two bytes.

此外,每个标记都可以在开头添加任意数量的FF.

Also, every marker can be padded in the beginning with any number of FF's.

当您进入FFD9时,您就已经结束了.

When you get to FFD9 you're at the end of the stream.

当然,您可以逐字阅读流,如果需要性能,可以搜索FF,但这是读者的练习. ;-)

Of course you could read the stream word by word, searching for FF if you want performance but that's left as an exercise for the reader. ;-)

这篇关于检测JPG图像的Eof的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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