社区
机器视觉
帖子详情
java能实现往jpeg图片中写入exif信息的功能吗?我找了好久只发现有读取的.没有写入的
flylyke
2004-11-20 08:34:34
如题
...全文
359
3
打赏
收藏
java能实现往jpeg图片中写入exif信息的功能吗?我找了好久只发现有读取的.没有写入的
如题
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
3 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
leonwu1981_2
2005-01-28
打赏
举报
回复
不就是个文件吗,了解格式的话直接用二进制流
chenweionline
2005-01-26
打赏
举报
回复
你了解了JPEG格式的文件头,可以在写二进制流的时候用自己的替换原有的。
zzwu
2004-11-21
打赏
举报
回复
exif信息是写在JPG图像文件的头部的,只要了解JPG图像的文件头,当然可以自己写入。
C#
读取
JPEG
图片
的
Exif
信息
[Serializable] public class
EXIF
{ #region -- Class level members -- // Class level members. private Image _picture; #endregion #region -- Constructors -- // Constructors. ///
/// This is default constructor of the
EXIF
class. ///
public
EXIF
() { } ///
/// This is base constructor of the
EXIF
class. ///
public
EXIF
(string filePath) { _picture = Image.FromFile(filePath); } #endregion #region -- Public methods -- ///
/// This method returns
EXIF
property values. ///
///
EXIF
property to be returned. public string Get
EXIF
Property(Definitions.
exif
Code
exif
Code) { // 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 (
exif
Code) { case Definitions.
exif
Code.ImageDescription: returnValue = ParsedString(Definitions.
exif
Code.ImageDescription); break; case Definitions.
exif
Code.Make: returnValue = ParsedString(Definitions.
exif
Code.Make); break; case Definitions.
exif
Code.Model: returnValue = ParsedString(Definitions.
exif
Code.Model); break; case Definitions.
exif
Code.Orientation: returnValue = Orientation(); break; case Definitions.
exif
Code.XResolution: returnValue = ParseResolution(Definitions.
exif
Code.XResolution); break; case Definitions.
exif
Code.YResolution: returnValue = ParseResolution(Definitions.
exif
Code.YResolution); break; case Definitions.
exif
Code.ResolutionUnit: returnValue = ResolutionUnit(); break; case Definitions.
exif
Code.Software: returnValue = ParsedString(Definitions.
exif
Code.Software); break; case Definitions.
exif
Code.DateTime: returnValue = ParsedDate(Definitions.
exif
Code.DateTime).ToString(); break; case Definitions.
exif
Code.WhitePoint: returnValue = WhitePoint(); break; case Definitions.
exif
Code.PrimaryChromaticities: returnValue = PrimaryChromaticities(); break; case Definitions.
exif
Code.YCbCrCoefficients: returnValue = YCbCrCoefficients(); break; case Definitions.
exif
Code.YCbCrPositioning: returnValue = YCbCrPositioning(); break; case Definitions.
exif
Code.ReferenceBlackWhite: returnValue = ReferenceBlackWhite(); break; case Definitions.
exif
Code.Copyright: returnValue = ParsedString(Definitions.
exif
Code.Copyright); break; case Definitions.
exif
Code.ExposureTime: returnValue = ExposureTime(); break; case Definitions.
exif
Code.FNumber: returnValue = FNumber(); break; case Definitions.
exif
Code.ExposureProgram: returnValue = ExposureProgram(); break; case Definitions.
exif
Code.ISOSpeedRatings: returnValue = UnformattedShort(Definitions.
exif
Code.ISOSpeedRatings); break; case Definitions.
exif
Code.
Exif
Version: returnValue = ParsedString(Definitions.
exif
Code.
Exif
Version); break; case Definitions.
exif
Code.DateTimeOriginal: returnValue = ParsedDate(Definitions.
exif
Code.DateTimeOriginal).ToString(); break; case Definitions.
exif
Code.DateTimeDigitized: returnValue = ParsedDate(Definitions.
exif
Code.DateTimeDigitized).ToString(); break; case Definitions.
exif
Code.ComponentsConfiguration: returnValue = ComponentsConfiguration(); break; case Definitions.
exif
Code.CompressedBitsPerPixel: returnValue = CompressedBitsPerPixel(); break; case Definitions.
exif
Code.ShutterSpeedValue: returnValue = ShutterSpeedValue(); break; case Definitions.
exif
Code.ApertureValue: returnValue = ApertureValue(); break; case Definitions.
exif
Code.BrightnessValue: returnValue = BrightnessValue(); break; case Definitions.
exif
Code.ExposureBiasValue: returnValue = ExposureBiasValue(); break; case Definitions.
exif
Code.MaxApertureValue: returnValue = MaxApertureValue(); break; case Definitions.
exif
Code.SubjectDistance: returnValue = SubjectDistance(); break; case Definitions.
exif
Code.MeteringMode: returnValue = MeteringMode(); break; case Definitions.
exif
Code.LightSource: returnValue = LightSource(); break; case Definitions.
exif
Code.Flash: returnValue = Flash(); break; case Definitions.
exif
Code.FocalLength: returnValue = FocalLength(); break; case Definitions.
exif
Code.MakerNote: returnValue = MakerNote(); break; case Definitions.
exif
Code.UserComment: returnValue = ParsedString(Definitions.
exif
Code.UserComment); break; case Definitions.
exif
Code.SubsecTime: returnValue = ParsedString(Definitions.
exif
Code.SubsecTime); break; case Definitions.
exif
Code.SubsecTimeOriginal: returnValue = ParsedString(Definitions.
exif
Code.SubsecTimeOriginal); break; case Definitions.
exif
Code.SubsecTimeDigitized: returnValue = ParsedString(Definitions.
exif
Code.SubsecTimeDigitized); break; case Definitions.
exif
Code.FlashpixVersion: returnValue = ParsedString(Definitions.
exif
Code.FlashpixVersion); break; case Definitions.
exif
Code.ColorSpace: returnValue = ColorSpace(); break; case Definitions.
exif
Code.RelatedSoundFile: returnValue = ParsedString(Definitions.
exif
Code.RelatedSoundFile); break; case Definitions.
exif
Code.FocalPlaneXResolution: returnValue = FocalPlaneXResolution(); break; case Definitions.
exif
Code.FocalPlaneYResolution: returnValue = FocalPlaneYResolution(); break; case Definitions.
exif
Code.FocalPlaneResolutionUnit: returnValue = ResolutionUnit(); break; case Definitions.
exif
Code.ExposureIndex: returnValue = ExposureIndex(); break; case Definitions.
exif
Code.SensingMethod: returnValue = SensingMethod(); break; case Definitions.
exif
Code.FileSource: returnValue = FileSource(); break; case Definitions.
exif
Code.SceneType: returnValue = SceneType(); break; case Definitions.
exif
Code.CFAPattern: returnValue = ParsedString(Definitions.
exif
Code.CFAPattern); break; case Definitions.
exif
Code.InteroperabilityIndex: returnValue = ParsedString(Definitions.
exif
Code.InteroperabilityIndex); break; case Definitions.
exif
Code.ImageWidth: returnValue = UnformattedShort(Definitions.
exif
Code.ImageWidth); break; case Definitions.
exif
Code.ImageLength: returnValue = UnformattedShort(Definitions.
exif
Code.ImageLength); ; break; case Definitions.
exif
Code.BitsPerSample: returnValue = BitsPerSample(); break; case Definitions.
exif
Code.Compression: returnValue = Compression(); break; case Definitions.
exif
Code.PhotometricInterpretation: returnValue = PhotometricInterpretation(); break; case Definitions.
exif
Code.StripOffsets: returnValue = StripOffsets(); break; case Definitions.
exif
Code.SamplesPerPixel: returnValue = UnformattedShort(Definitions.
exif
Code.SamplesPerPixel); break; case Definitions.
exif
Code.RowsPerStrip: returnValue = UnformattedShort(Definitions.
exif
Code.RowsPerStrip); break; case Definitions.
exif
Code.StripByteCounts: returnValue = StripByteCounts(); break; case Definitions.
exif
Code.PlanarConfiguration: returnValue = PlanarConfiguration(); break; case Definitions.
exif
Code.YCbCrSubSampling: returnValue = YCbCrSubSampling(); break; case Definitions.
exif
Code.ImageUniqueID: returnValue = ParsedString(Definitions.
exif
Code.ImageUniqueID); break; case Definitions.
exif
Code.
JPEG
InterchangeFormatLength: returnValue = UnformattedShort(Definitions.
exif
Code.
JPEG
InterchangeFormatLength); break; case Definitions.
exif
Code.TransferFunction: returnValue = "Not implemented."; break; case Definitions.
exif
Code.PixelXDimension: returnValue = UnformattedShort(Definitions.
exif
Code.PixelXDimension); break; case Definitions.
exif
Code.PixelYDimension: returnValue = UnformattedShort(Definitions.
exif
Code.PixelYDimension); break; case Definitions.
exif
Code.SpectralSensitivity: returnValue = ParsedString(Definitions.
exif
Code.SpectralSensitivity); break; case Definitions.
exif
Code.OECF: returnValue = ParsedString(Definitions.
exif
Code.OECF); break; case Definitions.
exif
Code.CustomRendered: returnValue = CustomRendered(); break; case Definitions.
exif
Code.ExposureMode: returnValue = ExposureMode(); break; case Definitions.
exif
Code.WhiteBalance: returnValue = WhiteBalance(); break; case Definitions.
exif
Code.DigitalZoomRatio: returnValue = DigitalZoomRatio(); break; case Definitions.
exif
Code.FocalLengthIn35mmFilm: returnValue = FocalLengthIn35mmFilm(); break; case Definitions.
exif
Code.SceneCaptureType: returnValue = SceneCaptureType(); break; case Definitions.
exif
Code.GainControl: returnValue = GainControl(); break; case Definitions.
exif
Code.Contrast: returnValue = Contrast(); break; case Definitions.
exif
Code.Saturation: returnValue = Saturation(); break; case Definitions.
exif
Code.Sharpness: returnValue = Sharpness(); break; case Definitions.
exif
Code.DeviceSettingDescription: returnValue = ParsedString(Definitions.
exif
Code.DeviceSettingDescription); break; case Definitions.
exif
Code.SubjectDistanceRange: returnValue = SubjectDistanceRange(); break; default: returnValue = "
EXIF
property not found."; break; } return returnValue; } catch { return "N/A"; } } #endregion #region --
EXIF
Methods -- ///
/// This method returns the bits per sample
EXIF
property. ///
private string BitsPerSample() { //Declare local variables. string returnValue = "
EXIF
property not found."; byte[] data = GetPropertyValue(Definitions.
exif
Code.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; } ///
/// This method returns the compression
EXIF
property. ///
private string Compression() { //Declare local variables. string returnValue = "
EXIF
property not found."; byte[] data = GetPropertyValue(Definitions.
exif
Code.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; } ///
/// This method returns the photometric interpretation
EXIF
property. ///
private string PhotometricInterpretation() { //Declare local variables. string returnValue = "
EXIF
property not found."; byte[] data = GetPropertyValue(Definitions.
exif
Code.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; } ///
/// This method returns the strip offsets
EXIF
property. ///
private string StripOffsets() { return "Not implemented."; } ///
/// This method returns the strip byte counts
EXIF
property. ///
private string StripByteCounts() { return "Not implemented."; } ///
/// This method returns the planar configuration
EXIF
property. ///
private string PlanarConfiguration() { //Declare local variables. string returnValue = "
EXIF
property not found."; byte[] data = GetPropertyValue(Definitions.
exif
Code.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; } ///
/// This method returns the YCbCr subsampling
EXIF
property. ///
private string YCbCrSubSampling() { //Declare local variables. string returnValue = "
EXIF
property not found."; byte[] data = GetPropertyValue(Definitions.
exif
Code.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; } ///
/// This method returns the orientation
EXIF
property. ///
private string Orientation() { //Declare local variables. string returnValue = "
EXIF
property not found."; byte[] data = GetPropertyValue(Definitions.
exif
Code.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; } ///
/// This method returns the resolution unit
EXIF
property. ///
private string ResolutionUnit() { //Declare local variables. string returnValue = "
EXIF
property not found."; byte[] resUnit = GetPropertyValue(Definitions.
exif
Code.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; } ///
/// This method returns the white point
EXIF
property. ///
private string WhitePoint() { string returnValue = "
EXIF
property not found.";
EXIF
Rational[] data = ParsedRationalArray(Definitions.
exif
Code.WhitePoint); if (data.Length > 0) { returnValue = data[0].Denominator.ToString() + ", " + data[1].Denominator.ToString(); } return returnValue; } ///
/// This method returns the primary chromaticities
EXIF
property. ///
private string PrimaryChromaticities() { string returnValue = "
EXIF
property not found.";
EXIF
Rational[] data = ParsedRationalArray(Definitions.
exif
Code.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; } ///
/// This method returns the YCbCr coefficients
EXIF
property. ///
private string YCbCrCoefficients() { string returnValue = "
EXIF
property not found.";
EXIF
Rational[] data = ParsedRationalArray(Definitions.
exif
Code.YCbCrCoefficients); if (data.Length > 0) { returnValue = data[0].Denominator.ToString() + ", " + data[1].Denominator.ToString() + ", " + data[2].Denominator.ToString(); } return returnValue; } ///
/// This method returns the YCbCr positioning
EXIF
property. ///
private string YCbCrPositioning() { //Declare local variables. string returnValue = ""; byte[] data = GetPropertyValue(Definitions.
exif
Code.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; } ///
/// This method returns the reference black white
EXIF
property. ///
private string ReferenceBlackWhite() { string returnValue = "
EXIF
property not found.";
EXIF
Rational[] data = ParsedRationalArray(Definitions.
exif
Code.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; } ///
/// This method returns the exposure time
EXIF
property. ///
private string ExposureTime() { //Declare local variables. string returnValue = "
EXIF
property not found.";
EXIF
Rational exposureTime = ParsedRational(Definitions.
exif
Code.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; } ///
/// This method returns the FNumber
EXIF
property. ///
private string FNumber() { //Declare local variables. string returnValue = "
EXIF
property not found.";
EXIF
Rational fNumber = ParsedRational(Definitions.
exif
Code.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; } ///
/// This method returns the exposure program
EXIF
property. ///
private string ExposureProgram() { //Declare local variables. string returnValue = "
EXIF
property not found."; byte[] data = GetPropertyValue(Definitions.
exif
Code.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; } ///
/// This method returns the components configuration
EXIF
property. ///
private string ComponentsConfiguration() { //Declare local variables. string returnValue = "
EXIF
property not found."; byte[] data = GetPropertyValue(Definitions.
exif
Code.ComponentsConfiguration); switch (data[0]) { case 1: returnValue = "YCbCr"; break; case 4: returnValue = "RGB"; break; default: returnValue = "Reserved"; break; } return returnValue; } ///
/// This method returns the compressed bits per pixel
EXIF
property. ///
// This method needs to fixed to return the correct value. private string CompressedBitsPerPixel() { //Declare local variables. string returnValue = "
EXIF
property not found.";
EXIF
Rational cbpp = ParsedRational(Definitions.
exif
Code.CompressedBitsPerPixel); //Translate the
EXIF
code into a readable value. if (!cbpp.Equals(null)) { returnValue = string.Format("{0}/{1}", cbpp.Numerator, cbpp.Denominator); } return returnValue; } ///
/// This method returns the aperture value
EXIF
property. ///
private string ApertureValue() { //Declare local variables. string returnValue = "
EXIF
property not found.";
EXIF
Rational fNumber = ParsedRational(Definitions.
exif
Code.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; } ///
/// This method returns the shutter speed value
EXIF
property. ///
private string ShutterSpeedValue() { //Declare local variables. string returnValue = "
EXIF
property not found."; returnValue = ExposureTime(); return returnValue; } ///
/// This method returns the subject distance
EXIF
property. ///
private string SubjectDistance() { //Declare local variables. string returnValue = "
EXIF
property not found.";
EXIF
Rational sd = ParsedRational(Definitions.
exif
Code.SubjectDistance); //Translate the
EXIF
code into a readable value. if (!sd.Equals(null)) { returnValue = string.Format("{0}", sd.Numerator); } return returnValue; } ///
/// This method returns the metering mode
EXIF
property. ///
private string MeteringMode() { //Declare local variables. string returnValue = "
EXIF
property not found."; byte[] data = GetPropertyValue(Definitions.
exif
Code.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; } ///
/// This method returns the light source
EXIF
property. ///
private string LightSource() { //Declare local variables. string returnValue = "
EXIF
property not found."; byte[] data = GetPropertyValue(Definitions.
exif
Code.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; } ///
/// This method returns the flash
EXIF
property. ///
private string Flash() { //Declare local variables. string returnValue = "
EXIF
property not found."; byte[] data = GetPropertyValue(Definitions.
exif
Code.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; } ///
/// This method returns the focal length
EXIF
property. ///
private string FocalLength() { //Declare local variables. string returnValue = "
EXIF
property not found.";
EXIF
Rational focalLength = ParsedRational(Definitions.
exif
Code.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; } ///
/// This method returns the maker note
EXIF
property. ///
private string MakerNote() { return "Not implemented."; } ///
/// This method returns the color space
EXIF
property. ///
private string ColorSpace() { //Declare local variables. string returnValue = "
EXIF
property not found."; byte[] data = GetPropertyValue(Definitions.
exif
Code.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; } ///
/// This method returns the focal plane x resolution
EXIF
property. ///
private string FocalPlaneXResolution() { //Declare local variables. string returnValue = "
EXIF
property not found.";
EXIF
Rational focalPlaneXRes = ParsedRational(Definitions.
exif
Code.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; } ///
/// This method returns the focal plane y resolution
EXIF
property. ///
private string FocalPlaneYResolution() { //Declare local variables. string returnValue = "
EXIF
property not found.";
EXIF
Rational focalPlaneYRes = ParsedRational(Definitions.
exif
Code.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; } ///
/// This method returns the exposure index
EXIF
property. ///
private string ExposureIndex() { //Declare local variables. string returnValue = "
EXIF
property not found.";
EXIF
Rational expIndex = ParsedRational(Definitions.
exif
Code.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; } ///
/// This method returns the sensing method
EXIF
property. ///
private string SensingMethod() { // Declare local variables. // Get the value for this
EXIF
property. byte[] data = GetPropertyValue(Definitions.
exif
Code.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; } ///
/// This method returns the file source
EXIF
property. ///
private string FileSource() { // Declare local variables. // Get the value for this
EXIF
property. byte[] data = GetPropertyValue(Definitions.
exif
Code.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; } ///
/// This method returns the scene type
EXIF
property. ///
private string SceneType() { // Declare local variables. // Get the value for this
EXIF
property. byte[] data = GetPropertyValue(Definitions.
exif
Code.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; } ///
/// This method returns the custom rendered
EXIF
property. ///
private string CustomRendered() { // Declare local variables. // Get the value for this
EXIF
property. byte[] data = GetPropertyValue(Definitions.
exif
Code.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; } ///
/// This method returns the exposure mode
EXIF
property. ///
private string ExposureMode() { // Declare local variables. // Get the value for this
EXIF
property. byte[] data = GetPropertyValue(Definitions.
exif
Code.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; } ///
/// This method returns the white balance
EXIF
property. ///
private string WhiteBalance() { // Declare local variables. // Get the value for this
EXIF
property. byte[] data = GetPropertyValue(Definitions.
exif
Code.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; } ///
/// This method returns the focal length in 35mm film
EXIF
property. ///
private string FocalLengthIn35mmFilm() { // Declare local variables. // Get the value for this
EXIF
property. byte[] data = GetPropertyValue(Definitions.
exif
Code.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; } ///
/// This method returns the scene capture type
EXIF
property. ///
private string SceneCaptureType() { // Declare local variables. // Get the value for this
EXIF
property. byte[] data = GetPropertyValue(Definitions.
exif
Code.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; } ///
/// This method returns the gain control
EXIF
property. ///
private string GainControl() { // Declare local variables. // Get the value for this
EXIF
property. byte[] data = GetPropertyValue(Definitions.
exif
Code.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; } ///
/// This method returns the contrast
EXIF
property. ///
private string Contrast() { // Declare local variables. // Get the value for this
EXIF
property. byte[] data = GetPropertyValue(Definitions.
exif
Code.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; } ///
/// This method returns the saturation
EXIF
property. ///
private string Saturation() { // Declare local variables. // Get the value for this
EXIF
property. byte[] data = GetPropertyValue(Definitions.
exif
Code.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; } ///
/// This method returns the sharpness
EXIF
property. ///
private string Sharpness() { // Declare local variables. // Get the value for this
EXIF
property. byte[] data = GetPropertyValue(Definitions.
exif
Code.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; } ///
/// This method returns the subject distance range
EXIF
property. ///
private string SubjectDistanceRange() { // Declare local variables. // Get the value for this
EXIF
property. byte[] data = GetPropertyValue(Definitions.
exif
Code.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; } ///
/// This method returns the subject location
EXIF
property. ///
private string SubjectLocation() { // Declare local variables. // Get the value for this
EXIF
property. byte[] data = GetPropertyValue(Definitions.
exif
Code.SubjectLocation); string returnValue = "
EXIF
property not found."; if (data.Length > 0) { returnValue = "(" + data[0].ToString() + ", " + data[1].ToString() + ")"; } return returnValue; } ///
/// This method returns the digital zoom ratio
EXIF
property. ///
private string DigitalZoomRatio() { //Declare local variables. string returnValue = "
EXIF
property not found.";
EXIF
Rational dzr = ParsedRational(Definitions.
exif
Code.DigitalZoomRatio); //Translate the
EXIF
code into a readable value. if (!dzr.Equals(null)) { returnValue = dzr.Numerator.ToString() + ":" + dzr.Denominator.ToString(); } return returnValue; } ///
/// This method returns the brightness value
EXIF
property. ///
private string BrightnessValue() { //Declare local variables. string returnValue = "
EXIF
property not found.";
EXIF
Rational data = ParsedRational(Definitions.
exif
Code.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; } ///
/// This method returns the max aperture value
EXIF
property. ///
private string MaxApertureValue() { //Declare local variables. string returnValue = "
EXIF
property not found.";
EXIF
Rational data = ParsedRational(Definitions.
exif
Code.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; } ///
/// This method returns the exposure bias value
EXIF
property. ///
private string ExposureBiasValue() { //Declare local variables. string returnValue = "
EXIF
property not found.";
EXIF
Rational data = ParsedRational(Definitions.
exif
Code.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. ///
/// This method retrieves the data from the propery items collection. ///
private byte[] GetPropertyValue(Definitions.
exif
Code
exif
Code) { return _picture.GetPropertyItem((int)
exif
Code).Value; } ///
/// This method returns string
EXIF
data. ///
private string ParsedString(Definitions.
exif
Code
exif
Code) { // Declare local variables. // Retrieve the data for this
EXIF
property. byte[] data = GetPropertyValue(
exif
Code); // 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; } ///
/// This method returns rational
EXIF
data. ///
private
EXIF
Rational ParsedRational(Definitions.
exif
Code
exif
Code) { // Declare local variables. // Retrieve the data for this
EXIF
property. byte[] data = GetPropertyValue(
exif
Code); // Parse the data.
EXIF
Rational parsed = new
EXIF
Rational(data); return parsed; } ///
/// This method returns an array of rational
EXIF
data. ///
private
EXIF
Rational[] ParsedRationalArray(Definitions.
exif
Code
exif
Code) { // Declare local variables. // Retrieve the data for this
EXIF
property. byte[] data = GetPropertyValue(
exif
Code); // Holds the return value.
EXIF
Rational[] parsed = null; int arraySize = (data.Length / 8); if (arraySize > 0) { parsed = new
EXIF
Rational[arraySize]; for (int i = 0; i < arraySize; i++) { parsed[i] = new
EXIF
Rational(data, i * 8); } } return parsed; } ///
/// This method returns date/time
EXIF
data. ///
private DateTime ParsedDate(Definitions.
exif
Code
exif
Code) { // Declare local variables. // Create a new date object. DateTime ret = new DateTime(1900, 1, 1, 0, 0, 0); // Parse the data. string date = ParsedString(
exif
Code); // Format the data. if (date.Length >= 19) {
读取
以及
写入
Jpg
图片
内的
Exif
信息
读取
和修改
Jpeg
图片
内的
Exif
信息
的单元,原版只能
读取
我稍作修改可以修改
Jpeg
的
信息
。
java
处理
EXIF
信息
方法
资料处理了关于照片
exif
的
信息
,着重处理了照片
中
的gps
信息
,
使用lib
exif
为
JPEG
图片
添加
EXIF
属性(新)
使用lib
exif
为
JPEG
图片
添加
EXIF
属性,支持交叉编译,在hi3519测试通过。
Exif
信息
读取
一个C++
实现
的
读取
照片的
exif
信息
,用Qt写了个简单的界面
机器视觉
4,499
社区成员
15,359
社区内容
发帖
与我相关
我的任务
机器视觉
图形图像/机器视觉
复制链接
扫一扫
分享
社区描述
图形图像/机器视觉
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章