从jpeg文件中提取缩略图 [英] Extract thumbnail from jpeg file

查看:291
本文介绍了从jpeg文件中提取缩略图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从jpeg中提取缩略图,而无需任何外部库.我的意思是这并不太困难,因为我需要知道缩略图的开始位置和结束位置,然后将其剪切即可.我研究了许多文档(例如: http://www.media.mit .edu/pia/Research/deepview/exif.html ),并尝试分析jpeg,但并非所有内容都清楚.我试图一步一步地跟踪字节,但在深处我感到困惑.是否有任何好的文档或可读的源代码来提取有关jpeg文件中缩略图开始和结束位置的信息?

I'd like to extract thumbnail image from jpegs, without any external library. I mean this is not too difficult, because I need to know where the thumbnail starts, and ends in the file, and simply cut it. I study many documentation ( ie.: http://www.media.mit.edu/pia/Research/deepview/exif.html ), and try to analyze jpegs, but not everything clear. I tried to track step by step the bytes, but in the deep I confused. Is there any good documentation, or readable source code to extract the info about thumbnail start and end position within a jpeg file?

谢谢!

推荐答案

对于大多数由电话或数码相机创建的JPEG图像,缩略图(如果存在)存储在APP1标记(FFE1)中.在该标记段内是一个TIFF文件,其中包含主图像的EXIF信息和作为​​JPEG压缩图像存储的可选缩略图. TIFF文件通常包含两个页面",其中第一页是EXIF信息,第二页是以旧" TIFF 6型格式存储的缩略图. Type 6格式是指将JPEG文件按原样存储在TIFF包装器中的情况.如果希望使用最简单的代码将缩略图提取为JFIF,则需要执行以下步骤:

For most JPEG images created by phones or digital cameras, the thumbnail image (if present) is stored in the APP1 marker (FFE1). Inside this marker segment is a TIFF file containing the EXIF information for the main image and the optional thumbnail image stored as a JPEG compressed image. The TIFF file usually contains two "pages" where the first page is the EXIF info and the second page is the thumbnail stored in the "old" TIFF type 6 format. Type 6 format is when a JPEG file is just stored as-is inside of a TIFF wrapper. If you want the simplest possible code to extract the thumbnail as a JFIF, you will need to do the following steps:

  1. 熟悉JFIF和TIFF标记/标签. JFIF标记由两个字节组成:0xFF,后跟标记类型(APP1为0xE1).这两个字节后面是按大端顺序存储的两个字节的长度.对于TIFF文件,请查阅Adobe TIFF 6.0参考.
  2. 在JPEG文件中搜索APP1(FFE1)EXIF标记.在APP1之前可能有多个APP1标记,并且可能有多个标记.
  3. 您要查找的APP1标记在长度字段后立即包含字母"EXIF".
  4. 查找"II"或"MM"(长度相距6个字节)以指示TIFF文件中使用的字节序. II =英特尔=小端,MM =摩托罗拉=大端.
  5. 跳过第一页的标签,找到存储图像的第二个IFD.在第二个页面"中,查找两个指向JPEG数据的TIFF标签.标签0x201具有JPEG数据的偏移量(相对于II/MM),标签0x202具有以字节为单位的长度.

这篇关于从jpeg文件中提取缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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