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

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

问题描述

我有很多不同图像大小的jpeg文件。例如,这里是由256 * 384(像素)的图像的hexdump给出的第一个640字节:

  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 .... ............

我猜这些尺寸信息在这些线。但是我无法看到哪些字节正确给出了大小。任何人都可以帮助我找到包含大小信息的字段?

解决方案

根据语法和结构部分的维基百科上的JPEG页面,图像的宽度和高度似乎不存储在图像本身中,或者至少不是以很容易找到的方式存储。





仍然引用 JPEG图像压缩常见问题,第1/2部分:


主题:[22]程序从JPEG
文件中提取图像尺寸?



JPEG文件的标题由
a系列的块组成,称为标记。
图像高度和宽度存储在类型为SOFn ($ Of
框架,类型N)
的标记中

要找到SOFn
,您必须跳过上述
标记;您不必知道其他类型的标记中的
是什么,只需
使用他们的长度字来跳过

所需的最小逻辑是
或许是一个C代码页。 (有些
的人建议只要搜索
代表SOFn,
的字节对,而不注意标记
块结构,这是不安全的
因为先前的标记可能包含
的SOFn模式,无论是机会还是
,因为它包含JPEG压缩的
缩略图,如果不遵循
标记结构,您将检索
缩略图的大小,而不是
主图像大小。)

rdjpgcom中可以找到一个大量的
注释的例子。 c在IJG分配
(见第2部分,项目15)。
Perl代码
可以在wwwis找到,从
http://www.tardis.ed.ac.uk/~ark/wwwis/


(呃,那个链接似乎坏了...)





这里有一部分可以帮助你的C代码, :解码JPEG(JFIF)文件的宽度和高度


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?

解决方案

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.


Still, quoting from JPEG image compression FAQ, part 1/2 :

Subject: [22] How can my program extract image dimensions from a JPEG file?

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, that link seems broken...)


Here's a portion of C code that could help you, though : Decoding the width and height of a JPEG (JFIF) file

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

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