jpeg图片的exif信息

       EXIF(Exchangeable Image File)是“可交换图像文件”的缩写,当中包含了专门为数码相机的照片而定制的元数

据,可以记录数码照片的拍摄参数、缩略图及其他属性信息。exif其实是jpeg文件的一种,遵从jpeg标准,只是在文件

头信息中增加了有关拍摄信息的内容和索引图。

        JEPG文件头必须以0xFF 0xD8开头,0xFF 0xD9结尾。然后后面会跟着出现以0xFF 0xE0为起始的application0,

0xFF 0xE1为起始的application1,以此类推。而exif信息就再app1里面。

        按照 Exif 标准对这些标识符的定义,数码相机可以把各种拍摄信息记入数码图像中,应用软件可以读取这些数据,

再按照 Exif 标准,检索出它们的具体含义,一般而言包括以下一些信息

 

标签号
Exif 定义名
中文定义名
备注
0x010EImageDescription图像描述-
0x013BArtist作者使用者的名字
0x010FMake生产商相机生产厂家
0x0110Model型号相机型号
0x0112Orientation方向有的相机支持,有的不支持
0x011AXResolution水平方向分辨率-
0x011BYResolution垂直方向分辨率-
0x0128ResolutionUnit分辨率单位-
0x0131Software软件固件Firmware版本或编辑软件
0x0132DateTime日期和时间照片最后的修改时间
0x0213YCbCrPositioningYCbCr定位色度抽样方法
0x8769ExifOffsetExif子IFD偏移量-
0x829A
ExposureTime曝光时间即快门速度
0x829DFNumber光圈系数光圈的F值
0x8822ExposureProgram曝光程序自动曝光、光圈优先、快门优先、M档等
0x8827ISOSpeedRatingsISO感光度Exif 2.3 中更新为 “PhotographicSensitivity”
0x9000ExifVersionExif 版本参见“历史版本”一节
0x9003DateTimeOriginal拍摄时间照片拍摄的时间
0x9004DateTimeDigitized数字化时间照片被写入内存卡的时间
0x9204ExposureBiasValue曝光补偿-
0x9205MaxApertureValue最大光圈APEX为单位
0x9207MeteringMode测光模式平均测光、中央重点测光、点测光等
0x9208Lightsource光源一般记录白平衡设定
0x9209Flash闪光灯记录闪光灯状态
0x920AFocalLength镜头焦距镜头物理焦距
0x927CMakerNote厂商注释参见“厂商注释”一节
0x9286UserComment用户注释用户自定义数据
0xA000FlashPixVersionFlashPix版本-
0xA001ColorSpace色彩空间一般为sRGB
0xA002ExifImageWidth图像宽度图像横向像素数
0xA003ExifImageLength图像高度图像纵向像素数
0xA433LensMake镜头生产商-
0xA434LensModel镜头型号-

下面单独对exif进行分析:

 

 

 

 

 

 

FF D8:jpeg文件起始标志

FF E1:app1标志,直接从app1开始,表示没有app0

00F4:app1的长度为244字节

45 78 69 66 00 00:“exif”字符串

49 49:表示小端,小端的时候要格外注意其取字符的时候是从后往前取,才能获得正确的数据。4D 4D表示大端。

2A 00:固定不变

08 00 00 00:固定不变,同时也是偏移量

05 00:表示有5个tag

 

接下来的,就是各个tag的详细信息:

 

每一个tag的长度都是12字节。

struct tag{

        short id;              //tag ID,比如上表的0x011A

        short format;      //数据格式,比如有些tag信息是数字,有的是文字

        int count;            //最多的字符个数

        offset;                 //偏移量

}

比如上图:

1A 01:表示ID为0x011A,查表可知,表示水平方向分辨率

05 00:表示有理数、03表示short、02表示ASCII

01 00 00 00:

4A 00 00 00:表示偏移量,因为具体的信息是在后面存储的。这里的偏移需要加上08 00 00 00 = 82字节,而偏移量

                       要从ff e1后面开始算上图从第五个字符字节开始。此处可偏移到00 00 00 48 00 00 00 01,因为是有理

                       数,所以前面是分子,后面是分母,总共8个字节。

接下来还会有4个tag信息。

参考文档:

http://www.cppblog.com/lymons/archive/2010/02/23/108266.aspx#ExifMarker

 

 

 

 

 

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
[Serializable] public class EXIF { #region -- Class level members -- // Class level members. private Image _picture; #endregion #region -- Constructors -- // Constructors. /// <summary> /// This is default constructor of the EXIF class. /// </summary> public EXIF() { } /// <summary> /// This is base constructor of the EXIF class. /// </summary> public EXIF(string filePath) { _picture = Image.FromFile(filePath); } #endregion #region -- Public methods -- /// <summary> /// This method returns EXIF property values. /// </summary> /// <param name="exifCode">EXIF property to be returned.</param> public string GetEXIFProperty(Definitions.exifCode exifCode) { // Declare local variables. string returnValue; try { // All of the EXIF properties will return strings to display in the control. // Some of the properties require additional formatting or massaging // of the data once it is returned. Those properties have their own // methods. switch (exifCode) { case Definitions.exifCode.ImageDescription: returnValue = ParsedString(Definitions.exifCode.ImageDescription); break; case Definitions.exifCode.Make: returnValue = ParsedString(Definitions.exifCode.Make); break; case Definitions.exifCode.Model: returnValue = ParsedString(Definitions.exifCode.Model); break; case Definitions.exifCode.Orientation: returnValue = Orientation(); break; case Definitions.exifCode.XResolution: returnValue = ParseResolution(Definitions.exifCode.XResolution); break; case Definitions.exifCode.YResolution: returnValue = ParseResolution(Definitions.exifCode.YResolution); break; case Definitions.exifCode.ResolutionUnit: returnValue = ResolutionUnit(); break; case Definitions.exifCode.Software: returnValue = ParsedString(Definitions.exifCode.Software); break; case Definitions.exifCode.DateTime: returnValue = ParsedDate(Definitions.exifCode.DateTime).ToString(); break; case Definitions.exifCode.WhitePoint: returnValue = WhitePoint(); break; case Definitions.exifCode.PrimaryChromaticities: returnValue = PrimaryChromaticities(); break; case Definitions.exifCode.YCbCrCoefficients: returnValue = YCbCrCoefficients(); break; case Definitions.exifCode.YCbCrPositioning: returnValue = YCbCrPositioning(); break; case Definitions.exifCode.ReferenceBlackWhite: returnValue = ReferenceBlackWhite(); break; case Definitions.exifCode.Copyright: returnValue = ParsedString(Definitions.exifCode.Copyright); break; case Definitions.exifCode.ExposureTime: returnValue = ExposureTime(); break; case Definitions.exifCode.FNumber: returnValue = FNumber(); break; case Definitions.exifCode.ExposureProgram: returnValue = ExposureProgram(); break; case Definitions.exifCode.ISOSpeedRatings: returnValue = UnformattedShort(Definitions.exifCode.ISOSpeedRatings); break; case Definitions.exifCode.ExifVersion: returnValue = ParsedString(Definitions.exifCode.ExifVersion); break; case Definitions.exifCode.DateTimeOriginal: returnValue = ParsedDate(Definitions.exifCode.DateTimeOriginal).ToString(); break; case Definitions.exifCode.DateTimeDigitized: returnValue = ParsedDate(Definitions.exifCode.DateTimeDigitized).ToString(); break; case Definitions.exifCode.ComponentsConfiguration: returnValue = ComponentsConfiguration(); break; case Definitions.exifCode.CompressedBitsPerPixel: returnValue = CompressedBitsPerPixel(); break; case Definitions.exifCode.ShutterSpeedValue: returnValue = ShutterSpeedValue(); break; case Definitions.exifCode.ApertureValue: returnValue = ApertureValue(); break; case Definitions.exifCode.BrightnessValue: returnValue = BrightnessValue(); break; case Definitions.exifCode.ExposureBiasValue: returnValue = ExposureBiasValue(); break; case Definitions.exifCode.MaxApertureValue: returnValue = MaxApertureValue(); break; case Definitions.exifCode.SubjectDistance: returnValue = SubjectDistance(); break; case Definitions.exifCode.MeteringMode: returnValue = MeteringMode(); break; case Definitions.exifCode.LightSource: returnValue = LightSource(); break; case Definitions.exifCode.Flash: returnValue = Flash(); break; case Definitions.exifCode.FocalLength: returnValue = FocalLength(); break; case Definitions.exifCode.MakerNote: returnValue = MakerNote(); break; case Definitions.exifCode.UserComment: returnValue = ParsedString(Definitions.exifCode.UserComment); break; case Definitions.exifCode.SubsecTime: returnValue = ParsedString(Definitions.exifCode.SubsecTime); break; case Definitions.exifCode.SubsecTimeOriginal: returnValue = ParsedString(Definitions.exifCode.SubsecTimeOriginal); break; case Definitions.exifCode.SubsecTimeDigitized: returnValue = ParsedString(Definitions.exifCode.SubsecTimeDigitized); break; case Definitions.exifCode.FlashpixVersion: returnValue = ParsedString(Definitions.exifCode.FlashpixVersion); break; case Definitions.exifCode.ColorSpace: returnValue = ColorSpace(); break; case Definitions.exifCode.RelatedSoundFile: returnValue = ParsedString(Definitions.exifCode.RelatedSoundFile); break; case Definitions.exifCode.FocalPlaneXResolution: returnValue = FocalPlaneXResolution(); break; case Definitions.exifCode.FocalPlaneYResolution: returnValue = FocalPlaneYResolution(); break; case Definitions.exifCode.FocalPlaneResolutionUnit: returnValue = ResolutionUnit(); break; case Definitions.exifCode.ExposureIndex: returnValue = ExposureIndex(); break; case Definitions.exifCode.SensingMethod: returnValue = SensingMethod(); break; case Definitions.exifCode.FileSource: returnValue = FileSource(); break; case Definitions.exifCode.SceneType: returnValue = SceneType(); break; case Definitions.exifCode.CFAPattern: returnValue = ParsedString(Definitions.exifCode.CFAPattern); break; case Definitions.exifCode.InteroperabilityIndex: returnValue = ParsedString(Definitions.exifCode.InteroperabilityIndex); break; case Definitions.exifCode.ImageWidth: returnValue = UnformattedShort(Definitions.exifCode.ImageWidth); break; case Definitions.exifCode.ImageLength: returnValue = UnformattedShort(Definitions.exifCode.ImageLength); ; break; case Definitions.exifCode.BitsPerSample: returnValue = BitsPerSample(); break; case Definitions.exifCode.Compression: returnValue = Compression(); break; case Definitions.exifCode.PhotometricInterpretation: returnValue = PhotometricInterpretation(); break; case Definitions.exifCode.StripOffsets: returnValue = StripOffsets(); break; case Definitions.exifCode.SamplesPerPixel: returnValue = UnformattedShort(Definitions.exifCode.SamplesPerPixel); break; case Definitions.exifCode.RowsPerStrip: returnValue = UnformattedShort(Definitions.exifCode.RowsPerStrip); break; case Definitions.exifCode.StripByteCounts: returnValue = StripByteCounts(); break; case Definitions.exifCode.PlanarConfiguration: returnValue = PlanarConfiguration(); break; case Definitions.exifCode.YCbCrSubSampling: returnValue = YCbCrSubSampling(); break; case Definitions.exifCode.ImageUniqueID: returnValue = ParsedString(Definitions.exifCode.ImageUniqueID); break; case Definitions.exifCode.JPEGInterchangeFormatLength: returnValue = UnformattedShort(Definitions.exifCode.JPEGInterchangeFormatLength); break; case Definitions.exifCode.TransferFunction: returnValue = "Not implemented."; break; case Definitions.exifCode.PixelXDimension: returnValue = UnformattedShort(Definitions.exifCode.PixelXDimension); break; case Definitions.exifCode.PixelYDimension: returnValue = UnformattedShort(Definitions.exifCode.PixelYDimension); break; case Definitions.exifCode.SpectralSensitivity: returnValue = ParsedString(Definitions.exifCode.SpectralSensitivity); break; case Definitions.exifCode.OECF: returnValue = ParsedString(Definitions.exifCode.OECF); break; case Definitions.exifCode.CustomRendered: returnValue = CustomRendered(); break; case Definitions.exifCode.ExposureMode: returnValue = ExposureMode(); break; case Definitions.exifCode.WhiteBalance: returnValue = WhiteBalance(); break; case Definitions.exifCode.DigitalZoomRatio: returnValue = DigitalZoomRatio(); break; case Definitions.exifCode.FocalLengthIn35mmFilm: returnValue = FocalLengthIn35mmFilm(); break; case Definitions.exifCode.SceneCaptureType: returnValue = SceneCaptureType(); break; case Definitions.exifCode.GainControl: returnValue = GainControl(); break; case Definitions.exifCode.Contrast: returnValue = Contrast(); break; case Definitions.exifCode.Saturation: returnValue = Saturation(); break; case Definitions.exifCode.Sharpness: returnValue = Sharpness(); break; case Definitions.exifCode.DeviceSettingDescription: returnValue = ParsedString(Definitions.exifCode.DeviceSettingDescription); break; case Definitions.exifCode.SubjectDistanceRange: returnValue = SubjectDistanceRange(); break; default: returnValue = "EXIF property not found."; break; } return returnValue; } catch { return "N/A"; } } #endregion #region -- EXIF Methods -- /// <summary> /// This method returns the bits per sample EXIF property. /// </summary> private string BitsPerSample() { //Declare local variables. string returnValue = "EXIF property not found."; byte[] data = GetPropertyValue(Definitions.exifCode.BitsPerSample); //Translate the EXIF code into a readable value. if (!data.Equals(null)) { returnValue = data[0].ToString() + " " + data[1].ToString() + " " + data[2].ToString(); } return returnValue; } /// <summary> /// This method returns the compression EXIF property. /// </summary> private string Compression() { //Declare local variables. string returnValue = "EXIF property not found."; byte[] data = GetPropertyValue(Definitions.exifCode.Compression); //Translate the EXIF code into a readable value. if (!data.Equals(null)) { switch (data[0]) { case 1: returnValue = "uncompressed"; break; case 6: returnValue = "JPEG compression (thumbnails only)"; break; default: returnValue = "reserved"; break; } } return returnValue; } /// <summary> /// This method returns the photometric interpretation EXIF property. /// </summary> private string PhotometricInterpretation() { //Declare local variables. string returnValue = "EXIF property not found."; byte[] data = GetPropertyValue(Definitions.exifCode.PhotometricInterpretation); //Translate the EXIF code into a readable value. if (data != null) { switch (data[0]) { case 2: returnValue = "RBG"; break; case 6: returnValue = "YCbCr"; break; default: returnValue = "reserved"; break; } } return returnValue; } /// <summary> /// This method returns the strip offsets EXIF property. /// </summary> private string StripOffsets() { return "Not implemented."; } /// <summary> /// This method returns the strip byte counts EXIF property. /// </summary> private string StripByteCounts() { return "Not implemented."; } /// <summary> /// This method returns the planar configuration EXIF property. /// </summary> private string PlanarConfiguration() { //Declare local variables. string returnValue = "EXIF property not found."; byte[] data = GetPropertyValue(Definitions.exifCode.PlanarConfiguration); //Translate the EXIF code into a readable value. if (data != null) { switch (data[0]) { case 1: returnValue = "chunky format"; break; case 2: returnValue = "planar format"; break; default: returnValue = "reserved"; break; } } return returnValue; } /// <summary> /// This method returns the YCbCr subsampling EXIF property. /// </summary> private string YCbCrSubSampling() { //Declare local variables. string returnValue = "EXIF property not found."; byte[] data = GetPropertyValue(Definitions.exifCode.YCbCrSubSampling); //Translate the EXIF code into a readable value. if (data != null) { switch (data[0]) { case 2: if (data[1] == 1) { returnValue = "YCbCr4:2:2"; } else { returnValue = "YCbCr4:2:0"; } break; default: returnValue = "reserved"; break; } } return returnValue; } /// <summary> /// This method returns the orientation EXIF property. /// </summary> private string Orientation() { //Declare local variables. string returnValue = "EXIF property not found."; byte[] data = GetPropertyValue(Definitions.exifCode.Orientation); //Translate the EXIF code into a readable value. if (data.Length > 0) { switch (data[0]) { case 1: returnValue = "The 0th row is at the visual top of the image, and the 0th column is the visual left-hand side."; break; case 2: returnValue = "The 0th row is at the visual top of the image, and the 0th column is the visual right-hand side."; break; case 3: returnValue = "The 0th row is at the visual bottom of the image, and the 0th column is the visual right-hand side."; break; case 4: returnValue = "The 0th row is at the visual bottom of the image, and the 0th column is the visual left-hand side."; break; case 5: returnValue = "The 0th row is at the visual left-hand side of the image, and the 0th column is the visual top."; break; case 6: returnValue = "The 0th row is at the visual right-hand side of the image, and the 0th column is the visual top."; break; case 7: returnValue = "The 0th row is at the visual right-hand side of the image, and the 0th column is the visual bottom."; break; case 8: returnValue = "The 0th row is at the visual left-hand side of the image, and the 0th column is the visual bottom."; break; default: returnValue = "Other"; break; } } return returnValue; } /// <summary> /// This method returns the resolution unit EXIF property. /// </summary> private string ResolutionUnit() { //Declare local variables. string returnValue = "EXIF property not found."; byte[] resUnit = GetPropertyValue(Definitions.exifCode.ResolutionUnit); //Translate the EXIF code into a readable value. if (resUnit != null) { switch (resUnit[0]) { case 2: returnValue = "inches"; break; case 3: returnValue = "centimeters"; break; default: returnValue = "reserved"; break; } } return returnValue; } /// <summary> /// This method returns the white point EXIF property. /// </summary> private string WhitePoint() { string returnValue = "EXIF property not found."; EXIFRational[] data = ParsedRationalArray(Definitions.exifCode.WhitePoint); if (data.Length > 0) { returnValue = data[0].Denominator.ToString() + ", " + data[1].Denominator.ToString(); } return returnValue; } /// <summary> /// This method returns the primary chromaticities EXIF property. /// </summary> private string PrimaryChromaticities() { string returnValue = "EXIF property not found."; EXIFRational[] data = ParsedRationalArray(Definitions.exifCode.PrimaryChromaticities); if (data.Length > 0) { returnValue = data[0].Denominator.ToString() + ", " + data[1].Denominator.ToString() + ", " + data[2].Denominator.ToString() + ", " + data[3].Denominator.ToString() + ", " + data[4].Denominator.ToString() + ", " + data[5].Denominator.ToString(); } return returnValue; } /// <summary> /// This method returns the YCbCr coefficients EXIF property. /// </summary> private string YCbCrCoefficients() { string returnValue = "EXIF property not found."; EXIFRational[] data = ParsedRationalArray(Definitions.exifCode.YCbCrCoefficients); if (data.Length > 0) { returnValue = data[0].Denominator.ToString() + ", " + data[1].Denominator.ToString() + ", " + data[2].Denominator.ToString(); } return returnValue; } /// <summary> /// This method returns the YCbCr positioning EXIF property. /// </summary> private string YCbCrPositioning() { //Declare local variables. string returnValue = ""; byte[] data = GetPropertyValue(Definitions.exifCode.YCbCrPositioning); //Translate the EXIF code into a readable value. if (data.Length > 0) { switch (data[0]) { case 1: returnValue = "centered"; break; case 2: returnValue = "co-sited"; break; default: returnValue = "reserved"; break; } } else { returnValue = "EXIF property not found."; } return returnValue; } /// <summary> /// This method returns the reference black white EXIF property. /// </summary> private string ReferenceBlackWhite() { string returnValue = "EXIF property not found."; EXIFRational[] data = ParsedRationalArray(Definitions.exifCode.ReferenceBlackWhite); if (data.Length > 0) { returnValue = "[" + data[0].Denominator.ToString() + ", " + data[1].Denominator.ToString() + ", " + data[2].Denominator.ToString() + ", " + data[3].Denominator.ToString() + ", " + data[4].Denominator.ToString() + ", " + data[5].Denominator.ToString() + "]"; } return returnValue; } /// <summary> /// This method returns the exposure time EXIF property. /// </summary> private string ExposureTime() { //Declare local variables. string returnValue = "EXIF property not found."; EXIFRational exposureTime = ParsedRational(Definitions.exifCode.ExposureTime); //Translate the EXIF code into a readable value. if (!exposureTime.Equals(null)) { if (exposureTime.Numerator == 0 && exposureTime.Denominator == 0) { returnValue = "N/A"; } else { returnValue = string.Format("{0}/{1} s", exposureTime.Numerator, exposureTime.Denominator); } } else { returnValue = "N/A"; } return returnValue; } /// <summary> /// This method returns the FNumber EXIF property. /// </summary> private string FNumber() { //Declare local variables. string returnValue = "EXIF property not found."; EXIFRational fNumber = ParsedRational(Definitions.exifCode.FNumber); //Translate the EXIF code into a readable value. if (!fNumber.Equals(null)) { returnValue = string.Format("f{0}", (float)(fNumber.Numerator / fNumber.Denominator)); } return returnValue; } /// <summary> /// This method returns the exposure program EXIF property. /// </summary> private string ExposureProgram() { //Declare local variables. string returnValue = "EXIF property not found."; byte[] data = GetPropertyValue(Definitions.exifCode.ExposureProgram); //Translate the EXIF code into a readable value. if (data.Length > 0) { switch (data[0]) { case 0: returnValue = "Not defined"; break; case 1: returnValue = "Manual"; break; case 2: returnValue = "Normal program"; break; case 3: returnValue = "Aperture priority"; break; case 4: returnValue = "Shutter priority"; break; case 5: returnValue = "Creative program (biased toward depth of field)"; break; case 6: returnValue = "Action program (biased toward fast shutter speed)"; break; case 7: returnValue = "Portrait mode (for closeup photos with the background out of focus)"; break; case 8: returnValue = "Landscape mode (for landscape photos with the background in focus)"; break; default: returnValue = "Reserved"; break; } } return returnValue; } /// <summary> /// This method returns the components configuration EXIF property. /// </summary> private string ComponentsConfiguration() { //Declare local variables. string returnValue = "EXIF property not found."; byte[] data = GetPropertyValue(Definitions.exifCode.ComponentsConfiguration); switch (data[0]) { case 1: returnValue = "YCbCr"; break; case 4: returnValue = "RGB"; break; default: returnValue = "Reserved"; break; } return returnValue; } /// <summary> /// This method returns the compressed bits per pixel EXIF property. /// </summary> // This method needs to fixed to return the correct value. private string CompressedBitsPerPixel() { //Declare local variables. string returnValue = "EXIF property not found."; EXIFRational cbpp = ParsedRational(Definitions.exifCode.CompressedBitsPerPixel); //Translate the EXIF code into a readable value. if (!cbpp.Equals(null)) { returnValue = string.Format("{0}/{1}", cbpp.Numerator, cbpp.Denominator); } return returnValue; } /// <summary> /// This method returns the aperture value EXIF property. /// </summary> private string ApertureValue() { //Declare local variables. string returnValue = "EXIF property not found."; EXIFRational fNumber = ParsedRational(Definitions.exifCode.FNumber); //Translate the EXIF code into a readable value. if (!fNumber.Equals(null)) { double av = Math.Round(2 * Math.Log(((fNumber.Numerator / fNumber.Denominator)), 2.00)); returnValue = string.Format("f{0}", (double)av); } return returnValue; } /// <summary> /// This method returns the shutter speed value EXIF property. /// </summary> private string ShutterSpeedValue() { //Declare local variables. string returnValue = "EXIF property not found."; returnValue = ExposureTime(); return returnValue; } /// <summary> /// This method returns the subject distance EXIF property. /// </summary> private string SubjectDistance() { //Declare local variables. string returnValue = "EXIF property not found."; EXIFRational sd = ParsedRational(Definitions.exifCode.SubjectDistance); //Translate the EXIF code into a readable value. if (!sd.Equals(null)) { returnValue = string.Format("{0}", sd.Numerator); } return returnValue; } /// <summary> /// This method returns the metering mode EXIF property. /// </summary> private string MeteringMode() { //Declare local variables. string returnValue = "EXIF property not found."; byte[] data = GetPropertyValue(Definitions.exifCode.MeteringMode); //Translate the EXIF code into a readable value. if (data.Length > 0) { switch (data[0]) { case 0: returnValue = "Unknown"; break; case 1: returnValue = "Average"; break; case 2: returnValue = "CenterWeightedAverage"; break; case 3: returnValue = "Spot"; break; case 4: returnValue = "MultiSpot"; break; case 5: returnValue = "Pattern"; break; case 6: returnValue = "Partial"; break; case 255: returnValue = "Other"; break; default: returnValue = "Reserved"; break; } } return returnValue; } /// <summary> /// This method returns the light source EXIF property. /// </summary> private string LightSource() { //Declare local variables. string returnValue = "EXIF property not found."; byte[] data = GetPropertyValue(Definitions.exifCode.LightSource); //Translate the EXIF code into a readable value. if (data.Length > 0) { switch (data[0]) { case 1: returnValue = "Daylight"; break; case 2: returnValue = "Fluorescent"; break; case 3: returnValue = "Tungsten (incandescent light)"; break; case 4: returnValue = "Flash"; break; case 9: returnValue = "Fine weather"; break; case 10: returnValue = "Cloudy weather"; break; case 11: returnValue = "Shade"; break; case 12: returnValue = "Daylight fluorescent (D 5700 - 7100K)"; break; case 13: returnValue = "Day white fluorescent (N 4600 - 5400K)"; break; case 14: returnValue = "Cool white fluorescent (W 3900 - 4500K)"; break; case 15: returnValue = "White fluorescent (WW 3200 - 3700K)"; break; case 17: returnValue = "Standard light A"; break; case 18: returnValue = "Standard light B"; break; case 19: returnValue = "Standard light C"; break; case 20: returnValue = "D55"; break; case 21: returnValue = "D65"; break; case 22: returnValue = "D75."; break; case 23: returnValue = "D50"; break; case 24: returnValue = "ISO studio tungsten"; break; case 255: returnValue = "other light source"; break; default: returnValue = "Reserved"; break; } } return returnValue; } /// <summary> /// This method returns the flash EXIF property. /// </summary> private string Flash() { //Declare local variables. string returnValue = "EXIF property not found."; byte[] data = GetPropertyValue(Definitions.exifCode.Flash); //Translate the EXIF code into a readable value. if (data.Length > 0) { switch (data[0]) { case 0: returnValue = "Flash did not fire."; break; case 1: returnValue = "Flash fired."; break; case 5: returnValue = "Strobe return light not detected."; break; case 7: returnValue = "Strobe return light detected."; break; case 9: returnValue = "Flash fired, compulsory flash mode."; break; case 13: returnValue = "Flash fired, compulsory flash mode, return light not detected."; break; case 15: returnValue = "Flash fired, compulsory flash mode, return light detected."; break; case 16: returnValue = "Flash did not fire, compulsory flash mode."; break; case 24: returnValue = "Flash did not fire, auto mode."; break; case 25: returnValue = "Flash fired, auto mode."; break; case 29: returnValue = "Flash fired, auto mode, return light not detected."; break; case 31: returnValue = "Flash fired, auto mode, return light detected."; break; case 32: returnValue = "No flash function."; break; case 65: returnValue = "Flash fired, red-eye reduction mode."; break; case 69: returnValue = "Flash fired, red-eye reduction mode, return light not detected."; break; case 71: returnValue = "Flash fired, red-eye reduction mode, return light detected."; break; case 73: returnValue = "Flash fired, compulsory flash mode, red-eye reduction mode."; break; case 77: returnValue = "Flash fired, compulsory flash mode, red-eye reduction mode, return light not detected."; break; case 79: returnValue = "Flash fired, compulsory flash mode, red-eye reduction mode, return light detected."; break; case 89: returnValue = "Flash fired, auto mode, red-eye reduction mode."; break; case 93: returnValue = "Flash fired, auto mode, return light not detected, red-eye reduction mode."; break; case 95: returnValue = "Flash fired, auto mode, return light detected, red-eye reduction mode."; break; default: returnValue = "Not defined, reserved."; break; } } return returnValue; } /// <summary> /// This method returns the focal length EXIF property. /// </summary> private string FocalLength() { //Declare local variables. string returnValue = "EXIF property not found."; EXIFRational focalLength = ParsedRational(Definitions.exifCode.FocalLength); //Translate the EXIF code into a readable value. if (!focalLength.Equals(null)) { if (focalLength.Numerator == 0 && focalLength.Denominator == 0) { returnValue = "N/A"; } else { returnValue = string.Format("{0:N0} mm", focalLength.Numerator * 1.0 / focalLength.Denominator); } } return returnValue; } /// <summary> /// This method returns the maker note EXIF property. /// </summary> private string MakerNote() { return "Not implemented."; } /// <summary> /// This method returns the color space EXIF property. /// </summary> private string ColorSpace() { //Declare local variables. string returnValue = "EXIF property not found."; byte[] data = GetPropertyValue(Definitions.exifCode.ColorSpace); //Translate the EXIF code into a readable value. if (data.Length > 0) { switch (data[0]) { case 1: returnValue = "sRGB"; break; case 255: returnValue = "Uncalibrated"; break; default: returnValue = "Reserved"; break; } } return returnValue; } /// <summary> /// This method returns the focal plane x resolution EXIF property. /// </summary> private string FocalPlaneXResolution() { //Declare local variables. string returnValue = "EXIF property not found."; EXIFRational focalPlaneXRes = ParsedRational(Definitions.exifCode.FocalPlaneXResolution); //Translate the EXIF code into a readable value. if (!focalPlaneXRes.Equals(null)) { returnValue = string.Format("{0:N0} mm", (focalPlaneXRes.Numerator * 1.0 / focalPlaneXRes.Denominator)); } return returnValue; } /// <summary> /// This method returns the focal plane y resolution EXIF property. /// </summary> private string FocalPlaneYResolution() { //Declare local variables. string returnValue = "EXIF property not found."; EXIFRational focalPlaneYRes = ParsedRational(Definitions.exifCode.FocalPlaneYResolution); //Translate the EXIF code into a readable value. if (!focalPlaneYRes.Equals(null)) { returnValue = string.Format("{0:N0} mm", focalPlaneYRes.Numerator * 1.0 / focalPlaneYRes.Denominator); } return returnValue; } /// <summary> /// This method returns the exposure index EXIF property. /// </summary> private string ExposureIndex() { //Declare local variables. string returnValue = "EXIF property not found."; EXIFRational expIndex = ParsedRational(Definitions.exifCode.ExposureIndex); //Translate the EXIF code into a readable value. if (!expIndex.Equals(null)) { returnValue = string.Format("{0:N0} mm", expIndex.Numerator * 1.0 / expIndex.Denominator); } return returnValue; } /// <summary> /// This method returns the sensing method EXIF property. /// </summary> private string SensingMethod() { // Declare local variables. // Get the value for this EXIF property. byte[] data = GetPropertyValue(Definitions.exifCode.SensingMethod); string returnValue = "EXIF property not found."; if (data.Length > 0) { switch (data[0]) { case 1: returnValue = "Not defined."; break; case 2: returnValue = "One-chip color area sensor."; break; case 3: returnValue = "Two-chip color area sensor."; break; case 4: returnValue = "Three-chip color area sensor."; break; case 5: returnValue = "Color sequential area sensor."; break; case 7: returnValue = "Trilinear sensor."; break; case 8: returnValue = "Color sequential linear sensor"; break; default: returnValue = "Reserved."; break; } } return returnValue; } /// <summary> /// This method returns the file source EXIF property. /// </summary> private string FileSource() { // Declare local variables. // Get the value for this EXIF property. byte[] data = GetPropertyValue(Definitions.exifCode.FileSource); string returnValue = "EXIF property not found."; if (data.Length > 0) { switch (data[0]) { case 3: returnValue = "DSC"; break; default: returnValue = "Reserved"; break; } } return returnValue; } /// <summary> /// This method returns the scene type EXIF property. /// </summary> private string SceneType() { // Declare local variables. // Get the value for this EXIF property. byte[] data = GetPropertyValue(Definitions.exifCode.FileSource); string returnValue = "EXIF property not found."; if (data.Length > 0) { switch (data[0]) { case 1: returnValue = "A directly photographed image."; break; default: returnValue = "Reserved."; break; } } return returnValue; } /// <summary> /// This method returns the custom rendered EXIF property. /// </summary> private string CustomRendered() { // Declare local variables. // Get the value for this EXIF property. byte[] data = GetPropertyValue(Definitions.exifCode.CustomRendered); string returnValue = "EXIF property not found."; if (data.Length > 0) { switch (data[0]) { case 0: returnValue = "Normal process"; break; case 1: returnValue = "Custom process"; break; default: returnValue = "Reserved"; break; } } return returnValue; } /// <summary> /// This method returns the exposure mode EXIF property. /// </summary> private string ExposureMode() { // Declare local variables. // Get the value for this EXIF property. byte[] data = GetPropertyValue(Definitions.exifCode.ExposureMode); string returnValue = "EXIF property not found."; if (data.Length > 0) { switch (data[0]) { case 0: returnValue = "Auto exposure"; break; case 1: returnValue = "Manual exposure"; break; case 2: returnValue = "Auto bracket"; break; default: returnValue = "Reserved"; break; } } return returnValue; } /// <summary> /// This method returns the white balance EXIF property. /// </summary> private string WhiteBalance() { // Declare local variables. // Get the value for this EXIF property. byte[] data = GetPropertyValue(Definitions.exifCode.WhiteBalance); string returnValue = "EXIF property not found."; if (data.Length > 0) { switch (data[0]) { case 0: returnValue = "Auto white balance"; break; case 1: returnValue = "Manual white balance"; break; default: returnValue = "Reserved"; break; } } return returnValue; } /// <summary> /// This method returns the focal length in 35mm film EXIF property. /// </summary> private string FocalLengthIn35mmFilm() { // Declare local variables. // Get the value for this EXIF property. byte[] data = GetPropertyValue(Definitions.exifCode.FocalLengthIn35mmFilm); string returnValue = "EXIF property not found."; if (data.Length > 0) { if (data[0] == 0) { returnValue = "Unknown"; } else if (data[0].ToString().Trim() == "NaN") { returnValue = "N/A"; } else { returnValue = data[0].ToString() + "mm"; } } return returnValue; } /// <summary> /// This method returns the scene capture type EXIF property. /// </summary> private string SceneCaptureType() { // Declare local variables. // Get the value for this EXIF property. byte[] data = GetPropertyValue(Definitions.exifCode.SceneCaptureType); string returnValue = "EXIF property not found."; if (data.Length > 0) { switch (data[0]) { case 0: returnValue = "Standard"; break; case 1: returnValue = "Landscape"; break; case 2: returnValue = "Portrait"; break; case 3: returnValue = "Night scene"; break; default: returnValue = "Reserved"; break; } } return returnValue; } /// <summary> /// This method returns the gain control EXIF property. /// </summary> private string GainControl() { // Declare local variables. // Get the value for this EXIF property. byte[] data = GetPropertyValue(Definitions.exifCode.GainControl); string returnValue = "EXIF property not found."; if (data.Length > 0) { switch (data[0]) { case 0: returnValue = "None"; break; case 1: returnValue = "Low gain up"; break; case 2: returnValue = "High gain up"; break; case 3: returnValue = "Low gain down"; break; case 4: returnValue = "High gain down"; break; default: returnValue = "Reserved"; break; } } return returnValue; } /// <summary> /// This method returns the contrast EXIF property. /// </summary> private string Contrast() { // Declare local variables. // Get the value for this EXIF property. byte[] data = GetPropertyValue(Definitions.exifCode.Contrast); string returnValue = "EXIF property not found."; if (data.Length > 0) { switch (data[0]) { case 0: returnValue = "Normal"; break; case 1: returnValue = "Soft"; break; case 2: returnValue = "Hard"; break; default: returnValue = "Reserved"; break; } } return returnValue; } /// <summary> /// This method returns the saturation EXIF property. /// </summary> private string Saturation() { // Declare local variables. // Get the value for this EXIF property. byte[] data = GetPropertyValue(Definitions.exifCode.Saturation); string returnValue = "EXIF property not found."; if (data.Length > 0) { switch (data[0]) { case 0: returnValue = "Normal"; break; case 1: returnValue = "Low saturation"; break; case 2: returnValue = "High saturation"; break; default: returnValue = "Reserved"; break; } } return returnValue; } /// <summary> /// This method returns the sharpness EXIF property. /// </summary> private string Sharpness() { // Declare local variables. // Get the value for this EXIF property. byte[] data = GetPropertyValue(Definitions.exifCode.Sharpness); string returnValue = "EXIF property not found."; if (data.Length > 0) { switch (data[0]) { case 0: returnValue = "Normal"; break; case 1: returnValue = "Soft"; break; case 2: returnValue = "Hard"; break; default: returnValue = "Reserved"; break; } } return returnValue; } /// <summary> /// This method returns the subject distance range EXIF property. /// </summary> private string SubjectDistanceRange() { // Declare local variables. // Get the value for this EXIF property. byte[] data = GetPropertyValue(Definitions.exifCode.SubjectDistanceRange); string returnValue = "EXIF property not found."; if (data.Length > 0) { switch (data[0]) { case 0: returnValue = "Unknown"; break; case 1: returnValue = "Macro"; break; case 2: returnValue = "Close view"; break; case 3: returnValue = "Distant view"; break; default: returnValue = "Reserved"; break; } } return returnValue; } /// <summary> /// This method returns the subject location EXIF property. /// </summary> private string SubjectLocation() { // Declare local variables. // Get the value for this EXIF property. byte[] data = GetPropertyValue(Definitions.exifCode.SubjectLocation); string returnValue = "EXIF property not found."; if (data.Length > 0) { returnValue = "(" + data[0].ToString() + ", " + data[1].ToString() + ")"; } return returnValue; } /// <summary> /// This method returns the digital zoom ratio EXIF property. /// </summary> private string DigitalZoomRatio() { //Declare local variables. string returnValue = "EXIF property not found."; EXIFRational dzr = ParsedRational(Definitions.exifCode.DigitalZoomRatio); //Translate the EXIF code into a readable value. if (!dzr.Equals(null)) { returnValue = dzr.Numerator.ToString() + ":" + dzr.Denominator.ToString(); } return returnValue; } /// <summary> /// This method returns the brightness value EXIF property. /// </summary> private string BrightnessValue() { //Declare local variables. string returnValue = "EXIF property not found."; EXIFRational data = ParsedRational(Definitions.exifCode.DigitalZoomRatio); //Translate the EXIF code into a readable value. if (!data.Equals(null)) { if ((long)data.Numerator >= Int32.MaxValue) { returnValue = "Unknown"; } else { returnValue = Math.Log(data.Numerator / data.Denominator, 2.0).ToString(); } } return returnValue; } /// <summary> /// This method returns the max aperture value EXIF property. /// </summary> private string MaxApertureValue() { //Declare local variables. string returnValue = "EXIF property not found."; EXIFRational data = ParsedRational(Definitions.exifCode.MaxApertureValue); //Translate the EXIF code into a readable value. if (!data.Equals(null)) { returnValue = string.Format("f{0}", (double)(data.Numerator / data.Denominator)); } return returnValue; } /// <summary> /// This method returns the exposure bias value EXIF property. /// </summary> private string ExposureBiasValue() { //Declare local variables. string returnValue = "EXIF property not found."; EXIFRational data = ParsedRational(Definitions.exifCode.ExposureBiasValue); //Translate the EXIF code into a readable value. if (!data.Equals(null)) { returnValue = string.Format("f{0}", (double)(data.Numerator / data.Denominator)); } return returnValue; } #endregion #region -- Private helper functions -- // Private helper functions. /// <summary> /// This method retrieves the data from the propery items collection. /// </summary> private byte[] GetPropertyValue(Definitions.exifCode exifCode) { return _picture.GetPropertyItem((int)exifCode).Value; } /// <summary> /// This method returns string EXIF data. /// </summary> private string ParsedString(Definitions.exifCode exifCode) { // Declare local variables. // Retrieve the data for this EXIF property. byte[] data = GetPropertyValue(exifCode); // Holds the return value. string parsed = ""; // If there's data, go ahead and parse it. if (data.Length > 1) { // Allocate some memory. IntPtr h = Marshal.AllocHGlobal(data.Length); int i = 0; foreach (byte b in data) { Marshal.WriteByte(h, i, b); i++; } parsed = Marshal.PtrToStringAnsi(h); Marshal.FreeHGlobal(h); } return parsed; } /// <summary> /// This method returns rational EXIF data. /// </summary> private EXIFRational ParsedRational(Definitions.exifCode exifCode) { // Declare local variables. // Retrieve the data for this EXIF property. byte[] data = GetPropertyValue(exifCode); // Parse the data. EXIFRational parsed = new EXIFRational(data); return parsed; } /// <summary> /// This method returns an array of rational EXIF data. /// </summary> private EXIFRational[] ParsedRationalArray(Definitions.exifCode exifCode) { // Declare local variables. // Retrieve the data for this EXIF property. byte[] data = GetPropertyValue(exifCode); // Holds the return value. EXIFRational[] parsed = null; int arraySize = (data.Length / 8); if (arraySize > 0) { parsed = new EXIFRational[arraySize]; for (int i = 0; i < arraySize; i++) { parsed[i] = new EXIFRational(data, i * 8); } } return parsed; } /// <summary> /// This method returns date/time EXIF data. /// </summary> private DateTime ParsedDate(Definitions.exifCode exifCode) { // Declare local variables. // Create a new date object. DateTime ret = new DateTime(1900, 1, 1, 0, 0, 0); // Parse the data. string date = ParsedString(exifCode); // Format the data. if (date.Length >= 19) {
部分使用说明: 点击开始菜单-运行命令,在对话框输入: "jhead –命令参数 jpeg文件" 例如: “jhead -de D:\A.jpg” 删除D盘盘根目录下A.jpg文件的exif信息。 “jhead -de D:\*.jpg” 删除D盘根目录下所有jpg文件的exif信息。其中星号是通配符。 二、通用指令参数 -te 将其他jpeg文件的eixf导入目标jpeg。例如"jhead –te D:\B.jpg D:\A.jpg" -dc 删除jpeg信息中的备注。注意,jpeg文件有两个备注,一是和其他文件一样的备注,另一个是exif信息中的备注。jhead仅对exif信息有效。 -de 完全删除exif信息。 -du 删除非原始exif信息,例如Photoshop、Turbophoto之类编辑后修改exif留下的信息。 -purejpg 删除所有jpeg文件非必须的信息。相当于-de、-dc和-du的集合,可以将文件减小数k。 -ce 修改文件的jpeg文件头部分备注(此备注并非exif信息)。该指令会打开文本编辑器,并在编辑器关闭时将备注信息存入文件。 -cs 导出备注。例如"jhead –cs D:\988.txt D:\A.jpg" -ci 导入备注。例如"jhead –ci D:\988.txt D:\A.jpg" -cl 直接输入备注。。例如"jhead –cl 我的备注 D:\A.jpg" 三、其他指令 时间日期 -ft 将jpeg文件的“修改时间”修改为exif信息中记录的时间。 -n[] 该指令会将文件名修改为exif信息中记录的“创建时间”;如果jpeg文件没有exif或者exif中的创建时间不可用,则将文件名修改为文件的“修改时间”。 默认的格式-顺序为MMDD-HHMMSS 格式-顺序参数如下: %d-日(01-31) %H-小时(00-23) %j-一年中的第几天(001-366) %m-月(01-12) %M-分钟(00-59) %S-秒(00-59) %U-一年中的第几周(00-53) %w-星期几(0-6,周日为0) %y-两位数纪年(00-99) %Y-四位数几年 %i-添加数字序号 例如: jhead -n%Y%m%d-%H%M%S d:\*.jpg 将所有jpg文件修改为YYYYMMDD-HHMMSS.jpg的格式。 -nf 与“-n”相同功能相同,不保留原文件名。 -a 修改不同扩展名的同名文件名,相机拍摄的avi短片exif信息存储在与其同名的thm文件中,可用此指令给avi文件更名。一般与“-n”指令共同使用。 -ta 修正时差,例如时差根据时区确定,例如+1:00或者-1:00 -da- 修正日期。日期格式是yyyy:mm:dd、yyyy:nn:dd+hh:mm或者 yyyy:mm:dd+hh:mm:ss。根据前后参数时间差调整exif的时间。 -ts 直接修改exif中的拍摄时间,日期-时间格式为yyyy:mm:dd-hh:mm:ss 缩略图 -dt 删除exif中的缩略图。这个缩略图一般为240x160像素,10k大小,用于数码相机、Windows XP查看照片,删除它不会影响工作。 -st 将exif中的缩略图复制为另一个jpeg文件 -rt 用另一个jpeg文件替换exif中的缩略图 -rgt[大小] 刷新exif缩略图,其中大小为缩略图的最大边长。 旋转 -autorot 根据exif中记录的水平方向信息转动jpeg照片。 -norot 清除exif中的水平方向信息。 四、使用技巧 1)用开始菜单的"运行"指令并不直观,可以通过运行cmd命令进入DOS命令提示符界面操作。在DOS界面进入操作照片文件夹(不懂DOS操作的朋友建议稍稍学习DOS指令,今后也会受用无穷),在文件夹中运行jhead命令,用“*.jpg”表示文件夹中所有的jpeg文件,可以进行批处理。 2)-te(复制exif信息)作用在于可以恢复被其他编辑软件删除的exif信息。编辑照片之前,先在照片文件夹中建立一个名为“backup”的备份文件夹,将原是照片复制到backup文件夹中,然后再编辑照片,编辑软件可能会删除或修改exif。编辑结束后进入DOS界面照片文件夹输入: jhead –te “backup\&i” *.jpg 照片的exif信息就会从backup文件夹的原始文件中复制回来。其中“&i”表示与目标文件同名的文件,前面的“backup\”表示原始文件位置。 3)-purejpg指令可以删除所有exif信息,让照片减小若干k字节

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值