jpeg图片属性读取

测试环境  Delphi XE

主要功能代码获取自其他作者

单元文件

unit utJpegInfo;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;typeTfrmJpegInfo = class(TForm)btnOpenJpeg: TButton;mmoJpegInfo: TMemo;procedure btnOpenJpegClick(Sender: TObject);private{ Private declarations }fsImage : TFileStream;i64RefPos : int64;//读取Jpeg信息procedure ReadJpegInfo(const JpegFileName : string);//读取byte值function GetByte: byte;//读取Word值function GetWord: word;//读取DWord值function GetDWord: DWord;//获取指定长度的字符串function GetString(intBufferSize: integer): string;//标签名称function GetTagName(wrdTag: Word): string;//读取Jpeg的标签信息procedure pReadIFD;public{ Public declarations }end;varfrmJpegInfo: TfrmJpegInfo;implementation{$R *.dfm}function TfrmJpegInfo.GetByte : byte;
beginfsImage.Read(result, 1);
end;function TfrmJpegInfo.GetWord : word;
beginresult := GetByte OR (GetByte SHL 8);
end;function TfrmJpegInfo.GetDWord : DWord;
beginresult := GetWord OR (GetWord SHL 16);
end;function TfrmJpegInfo.GetString(intBufferSize : integer) : string;
varstrResult : string;i : integer;
beginresult := '';for i := 1 to intBufferSize doresult := result + chr(GetByte);
end;function TfrmJpegInfo.GetTagName(wrdTag : Word) : string;
beginCase wrdTag of$001: result :='InteroperabilityIndex';$002: result :='InteroperabilityVersion';$0FE: result :='NewSubfileType';$0FF: result :='SubfileType';$100: result :='ImageWidth';$101: result :='ImageLength';$102: result :='BitsPerSample';$103: result :='Compression';$106: result :='PhotometricInterpretation';$10A: result :='FillOrder';$10D: result :='DocumentName';$10E: result :='ImageDescription';$10F: result :='Make';$110: result :='Model';$111: result :='StripOffsets';$112: result :='Orientation';$115: result :='SamplesPerPixel';$116: result :='RowsPerStrip';$117: result :='StripByteCounts';$11A: result :='XResolution';$11B: result :='YResolution';$11C: result :='PlanarConfiguration';$128: result :='ResolutionUnit';$12D: result :='TransferFunction';$131: result :='Software';$132: result :='DateTime';$13B: result :='Artist';$13D: result :='Predictor';$13E: result :='WhitePoint';$13F: result :='PrimaryChromaticities';$142: result :='TileWidth';$143: result :='TileLength';$144: result :='TileOffsets';$145: result :='TileByteCounts';$14A: result :='SubIFDs';$15B: result :='JPEGTables';$156: result :='TransferRange';$200: result :='JPEGProc';$201: result :='JPEGInterchangeFormat';$202: result :='JPEGInterchangeFormatLength';$211: result :='YCbCrCoefficients';$212: result :='YCbCrSubSampling';$213: result :='YCbCrPositioning';$214: result :='ReferenceBlackWhite';$1001: result :='Related Image Width';$1002: result :='Related Image Height';$828D: result :='CFARepeatPatternDim';$828E: result :='CFAPattern';$828F: result :='BatteryLevel';$8298: result :='Copyright';$829A: result :='ExposureTime';$829D: result :='FNumber';$83BB: result :='IPTC/NAA';$8769: result :='ExifOffset';$8773: result :='InterColorProfile';$8822: result :='ExposureProgram';$8824: result :='SpectralSensitivity';$8825: result :='GPSInfo';$8827: result :='ISOSpeedRatings';$8828: result :='OECF';$8829: result :='Interlace';$882A: result :='TimeZoneOffset';$882B: result :='SelfTimerMode';$9000: result :='ExifVersion';$9003: result :='DateTimeOriginal';$9004: result :='DateTimeDigitized';$9101: result :='ComponentsConfiguration';$9102: result :='CompressedBitsPerPixel';$9201: result :='ShutterSpeedValue';$9202: result :='ApertureValue';$9203: result :='BrightnessValue';$9204: result :='ExposureBiasValue';$9205: result :='MaxApertureValue';$9206: result :='SubjectDistance';$9207: result :='MeteringMode';$9208: result :='LightSource';$9209: result :='Flash';$920A: result :='FocalLength';$920B: result :='FlashEnergy';$920C: result :='SpatialFrequencyResponse';$920D: result :='Noise';$9211: result :='ImageNumber';$9212: result :='SecurityClassification';$9213: result :='ImageHistory';$9214: result :='SubjectLocation';$9215: result :='ExposureIndex';$9216: result :='TIFF/EPStandardID';$927C: result :='MakerNote';$9286: result :='UserComment';$9290: result :='SubSecTime';$9291: result :='SubSecTimeOriginal';$9292: result :='SubSecTimeDigitized';$A000: result :='FlashPixVersion';$A001: result :='ColorSpace';$A002: result :='ExifImageWidth';$A003: result :='ExifImageLength';$A005: result :='InteroperabilityOffset';$A20B: result :='FlashEnergy';$A20C: result :='SpatialFrequencyResponse';$A20E: result :='FocalPlaneXResolution';$A20F: result :='FocalPlaneYResolution';$A210: result :='FocalPlaneResolutionUnit';$A214: result :='SubjectLocation';$A215: result :='ExposureIndex';$A217: result :='SensingMethod';$A300: result :='FileSource';$A301: result :='SceneType';elseResult := 'Unknown Tag Type';end;end;procedure TfrmJpegInfo.pReadIFD;
varwrdNumberOfEntries : Word; //number of directory entrieswrdTag             : Word; //tag numberwrdDataType        : Word; //type or kind of data in entrydwdComponents      : DWord; //number of components in entrydwdData            : DWord; //data or offset to datawrdNextIFD         : Word; //offset to next IFDintLoop            : integer; //loop controlintDataLoop        : integer; //loop controlintTotalDataLength : integer; //total length of directory entry valuestrData            : string; //string directory entrybytData            : byte; //byte directory entrylngData            : longint; //long directory entryi64HoldPos         : int64; //hold position within filebegin//read number of entrieswrdNumberOfEntries := GetWord;mmoJpegInfo.lines.Add('Number of Entries:' + IntToStr(wrdNumberOfEntries));//read individual entriesfor intLoop := 1 to wrdNumberOfEntries dobegin//read tag number and interpretwrdTag := GetWord;strData := 'Tag: ' + GetTagName(wrdTag);//read tag type (kind of data) and interpretwrdDataType := GetWord;case wrdDataType of1 : strData := strData + ':(unsigned byte)'; //1 byte2 : strData := strData + ':(ascii strings)'; //1 byte3 : strData := strData + ':(unsigned short)'; //2 bytes4 : strData := strData + ':(unsigned long)'; //4 bytes5 : strData := strData + ':(unsigned rational)'; //8 bytes6 : strData := strData + ':(signed byte)'; //1 byte7 : strData := strData + ':(undefined)'; //1 byte8 : strData := strData + ':(signed short)'; //2 bytes9 : strData := strData + ':(signed long)'; //4 bytes10 : strData := strData + ':(signed rational)'; //8 bytes11 : strData := strData + ':(single float)'; //4 bytes12 : strData := strData + ':(double float)'; //8 byteselsemmoJpegInfo.lines.Add('Unknown Data Type');end; {case wrdDataType of}mmoJpegInfo.lines.Add(strData);//read number of componentsdwdComponents := GetDWord;//lstINFO.Items.Add('Number of Components:' + IntToStr(dwdComponents));//read data value or offset to data value{first check the total data length (bytes/component * # of componentsgives the total data length - if > 4 bytes then dwdData is the offsetto the data, if < 4 bytes then dwdData is the value itself}Case wrdDataType of1 : intTotalDataLength := dwdComponents; //1 byte2 : intTotalDataLength := dwdComponents; //1 byte3 : intTotalDataLength := dwdComponents * 2; //2 bytes4 : intTotalDataLength := dwdComponents * 4; //4 bytes5 : intTotalDataLength := dwdComponents * 8; //8 bytes6 : intTotalDataLength := dwdComponents; //1 byte7 : intTotalDataLength := dwdComponents; //1 byte8 : intTotalDataLength := dwdComponents * 2; //2 bytes9 : intTotalDataLength := dwdComponents * 4; //4 bytes10 : intTotalDataLength := dwdComponents * 8; //8 bytes11 : intTotalDataLength := dwdComponents * 4; //4 bytes12 : intTotalDataLength := dwdComponents * 8; //8 byteselseIntTotalDataLength := 0;end;//read the data valuedwdData := GetDWord;//set the hold positioni64HoldPos := fsImage.Position;//now set data or read offsetif intTotalDataLength > 4 thenbegin //read offset value//seek to offset valuefsImage.Seek(dwdData+i64RefPos,soFromBeginning);//read specific data type (unsigned byte)if wrdDataType = 1 then //unsigned bytebeginbytData := GetByte;mmoJpegInfo.lines.Add('Value=' + IntToStr(bytData));end; {wrdDataType=1}//read specific data type (string)if wrdDataType = 2 then //ascii stringbeginstrData := '';for intDataLoop := 1 to dwdComponents dostrData := strData + chr(GetByte);mmoJpegInfo.lines.Add('Value=' + strData);end; {wrdDataType=2}//read specific data type (unsigned short)if wrdDataType = 3 thenbeginfor intDataLoop := 1 to dwdComponents dostrData := strData + chr(GetByte);mmoJpegInfo.lines.Add('Value=' + strData);end; {wrdDataType=3}//read specific data type (unsigned long)if wrdDataType = 4 thenbeginlngData := GetDWord;mmoJpegInfo.lines.Add('Value:=' + IntToStr(lngData));end; {wrdDataType=4}//read specific data type (unsigned rational)if wrdDataType = 5 thenbeginstrData := IntToStr(GetDWord) + '/' + IntToStr(GetDWord);mmoJpegInfo.lines.Add('Value:=' + strData);end; {wrdDataType=5}end {intTotalDataLength > 4}elsebegin //read value intTotalDataLength < 4mmoJpegInfo.lines.Add('Value=' + IntToStr(dwdData));end; //read value intTotalDataLength < 4//return to former data positionfsImage.Seek(i64HoldPos,soFromBeginning);end; {for intLoop}//finally, read the offset to the next IFDwrdNextIFD := GetWord;end;procedure TfrmJpegInfo.ReadJpegInfo(const JpegFileName : string);
varwrdImage  : word; //word read from image filedwdImage  : dword; //double word read from image filebytImage  : byte; //byte read from image filestrImage  : string; //string read from image file
begin{open the file}fsImage := TFileStream.Create(JpegFileName,fmOpenRead);{show file path on caption}Caption := JpegFileName;{look for start-of-image marker FF D8 as first two bytes}if GetByte = $FF thenbeginif GetByte = $D8 thenmmoJpegInfo.lines.Add('Start-Of-Image Marker Found: Valid Image')elsebegin //exit if invalid imagemmoJpegInfo.lines.Add('Start-Of-Image Marker NOT Found: Invalid Image');exit;end; //check for soi markerend;{look for exif marker}while bytImage <> $D9 do  //$D9=eof bytebeginfsImage.Read(bytImage,1);  //read one byte//if exif marker found (starts by $FFE1}if bytImage = $FF thenif GetByte = $E1 thenbeginmmoJpegInfo.lines.Add('EXIF Marker Found');//now read image information{read exif data size}wrdImage := GetWord;mmoJpegInfo.lines.Add('Exif Data Size=' + Inttostr(wrdImage));{read actual exif header}strImage := GetString(4);if strImage <> 'Exif' thenexitelsemmoJpegInfo.lines.Add('Header: ' + strImage);//read two null bytes after exif headerGetWord;//set reference position for future offsetsi64RefPos := fsImage.Position;//the next 8 bytes are the TIFF header//2 bytes to determine byte order//2 bytes (002A or 2A00)//4 bytes offset to first image file directory{now read byte order, II is intel (little endian),MM is motorola (big endian)}wrdImage := GetWord;Case wrdImage of$4949 : mmoJpegInfo.lines.Add('Encoding: Little Endian');$4D4D : mmoJpegInfo.lines.Add('Encoding: Big Endian');elsemmoJpegInfo.lines.Add('Unknown Encoding');end;{read the next two bytes - always $02AA or $2A00}wrdImage := GetWord;{read the end of the tiff header - 4 bytescontain offset to first IFD}dwdImage := GetDWord;mmoJpegInfo.lines.Add('Offset to 1st IFD:' + IntToStr(dwdImage));{seek to first IFD, subtract 8 bytes forTIFF header}fsImage.Seek(dwdImage-8,soFromCurrent);{read the first image file directory}pReadIFD;end; //if exif marker foundend; {look for exif marker - while bytSOI <> $D9 do}{close the file}fsImage.Free;end; {read information from the jpeg file}procedure TfrmJpegInfo.btnOpenJpegClick(Sender: TObject);
beginmmoJpegInfo.Clear;with TOpenDialog.Create(self) dobeginOptions := [ofHideReadOnly, ofFileMustExist];Filter := '*.jpeg|*.jpg';if Execute thenbeginReadJpegInfo(FileName);end;free;end;
end;end.

窗体文件

object frmJpegInfo: TfrmJpegInfoLeft = 0Top = 0Caption = 'frmJpegInfo'ClientHeight = 564ClientWidth = 366Color = clBtnFaceFont.Charset = DEFAULT_CHARSETFont.Color = clWindowTextFont.Height = -12Font.Name = 'Tahoma'Font.Style = []OldCreateOrder = FalsePixelsPerInch = 106TextHeight = 14object btnOpenJpeg: TButtonLeft = 16Top = 16Width = 75Height = 25Caption = #25171#24320'Jpeg'TabOrder = 0OnClick = btnOpenJpegClickendobject mmoJpegInfo: TMemoLeft = 0Top = 47Width = 366Height = 517Align = alBottomScrollBars = ssVerticalTabOrder = 1end
end

Jpeg图片属性读取EXIF相关推荐

  1. jpg读取exif属性值

    项目在开发过程中,需要读取JPG影像中的exif的GPS,相机参数,影像大小等参数,根据exif属性的格式定义,解析所需要信息的字段,成功提取内容. Exif 编辑 Exif是一种图像文件格式,它的数 ...

  2. android android 修改 jpg exif 属性,Android开发之使用ExifInterface获取拍照后的图片属性...

    本文实例讲述了Android开发之使用ExifInterface获取拍照后的图片属性.分享给大家供大家参考,具体如下: ExifInterface exif = new ExifInterface(f ...

  3. 用python读取图像_Python读取图片属性信息的实现方法

    本文是利用Python脚本读取图片信息,有几个说明如下: 1.没有实现错误处理 2.没有读取所有信息,大概只有 GPS 信息.图片分辨率.图片像素.设备商.拍摄设备等 3.简单修改后应该能实现暴力修改 ...

  4. w806开发板驱动ov2640读取jpeg图片1600x1200分辨率,以及花屏原因及解决办法

    主频需要160MHz以上,80MHz主频读取会丢数据,读取过程中要关闭所有中断否则会出现丢数据花屏现象,还有一个重要的地方需要注意,PCLK速度过慢同时照片信息量多时,jpeg文件过大也会花一部分,像 ...

  5. Java获取图片属性(长,宽,大小,类型。。)/ EXIF

    获取图片属性(长,宽,大小,类型..)/ EXIF 注:在遇到大的图片或者并发操作时,第一种方法可能会造成内存泄漏,cpu飙高等问题,建议使用第二种: 1.通过java自带的流操作: @Testpub ...

  6. emwin读取sd图片_第12章emwin(ucgui)jpeg图片显示.pdf

    您所在位置:网站首页 > 海量文档 &nbsp>&nbsp计算机&nbsp>&nbspwindows相关 第12章emwin(ucgui)jpeg图片 ...

  7. CompactExifLib:访问JPEG文件中的EXIF标签

    目录 介绍 背景 演示应用程序 使用代码 读写标签 标签ID和图像文件目录(IFD) 标签类型 整数 数组标签 字符串 有理数 日期和时间 原始数据和字节顺序 移除标签 加载和保存EXIF数据 GPS ...

  8. Python用pyexiv2读写图片元数据(EXIF、IPTC、XMP)

    图片元数据是什么? 如何编辑? 图片元数据是什么? 图片元数据(metadata)是嵌入到图片文件中的一些标签.比较像文件属性,但是种类繁多.常见的几种标准有: EXIF:通常被数码相机在拍摄照片时自 ...

  9. JPEG系列一 JPEG图片的文件格式

    JPEG图片的文件格式 互联网上广泛使用的image/jpeg 图片,准确来说,全称应该叫做使用 JPEG标准压缩图像,使用JFIF标准封装图像数据的图形文件. JPEG 是一个压缩标准,JFIF 是 ...

最新文章

  1. 详细的线程池讲解,手写C与C++版本
  2. 使用fork并发处理多个client的请求和对等通信p2p
  3. C语言经典例86-两个字符串连接
  4. css3 text-shadow 为网页字体添加阴影
  5. 北斗导航 | 坐标转换:ECEF转LLA:GPS坐标系:WGS84(matlab代码)
  6. mysql隔离级别 举例_mysql的事务隔离级别举例
  7. 利用ioctl获取本机指定设备的MAC地址
  8. Springboot项目启动:报错The last packet sent successfully to the server was 0 milliseconds ago
  9. java取余数的函数_左神算法基础:哈希函数和哈希表
  10. 论跨境电商ERP系统与wms仓储管理系统之间有何区别和联系?
  11. python小白从哪来开始-python 从小白开始 - 内置函数
  12. “移”网打尽:网络即服务
  13. 即时通讯源码php开源版下载附安装教程+演示
  14. 怎么样可以通过阿里云APP进行备案 阿里云备案一般多长时间
  15. 代挂管家易开源7.4+web版
  16. visio2010画图
  17. 3.7V转12V2A 15V2A 大功率升压芯片 拉杆音响专用升压芯片
  18. json标准格式举例_json几个小例子
  19. 【架构风格】架构风格演进和领域架构分类
  20. C—— warning: function returns address of local variable(函数参数返回错误)

热门文章

  1. 当你的兴趣成为了职业
  2. MySQL数据快速导出导入
  3. 【C++】拷贝构造函数的调用时机
  4. 如何用scrm企业微信管理系统改善客户管理?
  5. 安装ubuntu18.04分区设置
  6. PB调用动态SQL语句
  7. 【分类】在分类中如何处理训练集中不平衡问题
  8. oracle 怎么使用跟踪,Oracle 10046跟踪事件使用方法
  9. AnimatorSet组合动画的笔记
  10. ArcEngine符号化——点符号选择器