private static double ReadRational(IFD_TAGS tag, PropertyItem item) { if (item.Id != (int)tag) { throw new EXIF_Exception(tag); } using (System.IO.MemoryStream mem = new System.IO.MemoryStream(item.Value)) { System.IO.BinaryReader reader = new System.IO.BinaryReader(mem); uint nom; uint denom; if (item.Type == (int)IFD_TYPES.RATIONAL) { nom = reader.ReadUInt32(); denom = reader.ReadUInt32(); if (nom == uint.MaxValue) { return(double.PositiveInfinity); } if (nom == 0) { return(double.NaN); } return(nom / denom); } else if (item.Type == (int)IFD_TYPES.SHORT) { nom = reader.ReadUInt16(); if (nom == ushort.MaxValue) { return(double.PositiveInfinity); } if (nom == 0) { return(double.NaN); } return(nom); } else { throw new EXIF_Exception(tag); } } }
private static int ReadExifInt(IFD_TAGS tag, PropertyItem item) { if (item.Id != (int)tag) { throw new EXIF_Exception(tag); } using (System.IO.MemoryStream mem = new System.IO.MemoryStream(item.Value)) { System.IO.BinaryReader reader = new System.IO.BinaryReader(mem); if (item.Type == (int)IFD_TYPES.SHORT) { return((int)reader.ReadUInt16()); } else if (item.Type == (int)IFD_TYPES.LONG) { return((int)reader.ReadUInt32()); } else { throw new EXIF_Exception(tag); } } }
public EXIF_Exception(IFD_TAGS tag) { this.tag = tag; }