从二进制的JPEG图像获取大小 [英] Getting Image size of JPEG from its binary

查看:1352
本文介绍了从二进制的JPEG图像获取大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有很多的JPEG文件有不同的图像大小。举例来说,这里是第640个字节按大小的图像hexdump都给出256 * 384(像素):

Hi I have a lot of jpeg files with varying image size. For instance, here is the first 640 bytes as given by hexdump of an image of size 256*384(pixels):

0000000: ffd8 ffe0 0010 4a46 4946 0001 0101 0048  ......JFIF.....H
0000010: 0048 0000 ffdb 0043 0003 0202 0302 0203  .H.....C........
0000020: 0303 0304 0303 0405 0805 0504 0405 0a07  ................
0000030: 0706 080c 0a0c 0c0b 0a0b 0b0d 0e12 100d  ................

我猜大小的信息是每亩这些线路中。但我无法看到哪些字节正确地给大小。谁能帮我看看,包含尺寸信息字段?

I guess the size information mus be within these lines. But am unable to see which bytes give the sizes correctly. Can anyone help me find the fields that contains the size information?

推荐答案

按照语法和结构部分维基百科上上 JPEG页的,宽度和图像高度似乎没有被存储在图像本身中 - - 或者,至少,不的方式,是很容易找到

According to the Syntax and structure section of the JPEG page on wikipedia, the width and height of the image don't seem to be stored in the image itself -- or, at least, not in a way that's quite easy to find.

结果
不过,从
JPEG图像融为一体pression常见问题解答,部分报价1/2

主题:[22]如何从一个JPEG我的程序提取图像尺寸
  文件?

JPEG文件的头由
  一系列块,被称为标记。
  图片的高度和宽度都存储
  类型SOFn
(开始的一个标志
  帧,N型)
的。结果为了找到SOFn
  您必须跳过了preceding
  标记;你不必知道什么是
  在其他类型的标记,只是
  用他们的话长跳过
  他们。结果所需的最低逻辑
  也许是第C code的。结果的(有些
  人们已经建议只是在寻找
  对于字节对重presenting SOFn,
  而不注意标记
  块结构。这是不安全
  因为事先标记可能包含
  在SOFn模式,无论是偶然还是
  因为它包含了一个JPEG-COM pressed
  缩略图。如果你不遵守
  标记结构,你将检索
  缩略图的大小,而不是
  主图像大小。)
的结果一大汗
  用C注释过的例子中可以找到
  rdjpgcom.c在IJG分布
  (见第2部分,第15项)。结果Perl的code
  可以在wwwis可以发现,从
   http://www.tardis.ed.ac.uk/~ark/wwwis/

The header of a JPEG file consists of a series of blocks, called "markers". The image height and width are stored in a marker of type SOFn (Start Of Frame, type N).
To find the SOFn you must skip over the preceding markers; you don't have to know what's in the other types of markers, just use their length words to skip over them.
The minimum logic needed is perhaps a page of C code.
(Some people have recommended just searching for the byte pair representing SOFn, without paying attention to the marker block structure. This is unsafe because a prior marker might contain the SOFn pattern, either by chance or because it contains a JPEG-compressed thumbnail image. If you don't follow the marker structure you will retrieve the thumbnail's size instead of the main image size.)
A profusely commented example in C can be found in rdjpgcom.c in the IJG distribution (see part 2, item 15).
Perl code can be found in wwwis, from http://www.tardis.ed.ac.uk/~ark/wwwis/.

(Ergh,该链接似乎打破...)

结果
下面是一个可以帮助你C code的部分,虽然:解码JPEG(JFIF)文件的宽度和高度

这篇关于从二进制的JPEG图像获取大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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