Using System; Using System. Collections. Generic; Using System. Text; Using System. Drawing; Using System. Drawing. Imaging;Namespace Console_Application { Class Program { Public static void Main (string [] args) { Dictionary <string, string> exif = new Dictionary <string, string> (); Image image = Image. FromFile (@ "e: \ www \ test.jpg "); PropertyItem [] properties = image. PropertyItems; Foreach (PropertyItem property in properties) { Switch (property. Id) { // Exif Case 0x010E: Exif ["ImageTitle"] = ASCIIToString (property. Value ); Break; Case 0x010F: Exif ["Make"] = ASCIIToString (property. Value ); Break; Case 0x0110: Exif ["Model"] = ASCIIToString (property. Value ); Break; Case 0x0112: Exif ["Orientation"] = jsontostring (property. Value, 0 ); Break; Case 0x011A: Exif ["XResolution"] = RationalToSingle (property. Value, 0 ); Break; Case 0x011B: Exif ["YResolution"] = RationalToSingle (property. Value, 0 ); Break; Case 0x0128: Exif ["ResolutionUnit"] = jsontostring (property. Value, 0 ); Break; Case 0x0131: Exif ["Software"] = ASCIIToString (property. Value ); Break; Case 0x0132: Exif ["DateTime"] = ASCIIToString (property. Value ); Break; // GPS Case 0x0002: Exif ["GPSLatitude"] = string. Format ("{0} ° {1} '{2 }″", RationalToSingle (property. Value, 0 ), RationalToSingle (property. Value, 8 ), RationalToSingle (property. Value, 16) ); Break; Case 0x0004: Exif ["gpslongpolling"] = string. Format ("{0} ° {1} '{2 }″", RationalToSingle (property. Value, 0 ), RationalToSingle (property. Value, 8 ), RationalToSingle (property. Value, 16) ); Break; Case 0x0006: Exif ["GPSAltitude"] = RationalToSingle (property. Value, 0 ); Break; } } Foreach (KeyValuePair <string, string> kvp in exif) Console. WriteLine (kvp. Key + ":" + kvp. Value ); Console. ReadKey (true ); }
// Method Static string ByteToString (byte [] B, int startindex) { If (startindex + 1 <= B. Length) Return (char) B [startindex]). ToString (); Else Return string. Empty; } Static string comment tostring (byte [] B, int startindex) { If (startindex + 2 <= B. Length) Return BitConverter. ToInt16 (B, startindex). ToString (); Else Return string. Empty; } Static string RationalToSingle (byte [] B, int startindex) { If (startindex + 8 <= B. Length) Return (BitConverter. ToSingle (B, startindex)/BitConverter. ToSingle (B, startindex + 4). ToString (); Else Return string. Empty; } Static string ASCIIToString (byte [] B) { Return Encoding. ASCII. GetString (B ); } } } |