C # exif information
Public void FindExifinfo (string filePath) {Image img = Image. fromFile (filePath); PropertyItem [] pt = img. propertyItems; for (int I = 0; I <pt. length; I ++) {PropertyItem p = pt [I]; switch (pt [I]. id) {// device manufacturer 20. case 0x010F: this. textBox1.Text = System. text. ASCIIEncoding. ASCII. getString (pt [I]. value); break; case 0x0110: // device model 25. this. textBox4.Text = GetValueOfType2 (p. value); break; case 0x0132: // photo time 30. this. textBox2.Text = GetValueOfType2 (p. value); break; case 0x829A ://. exposure time this. textBox3.Text = GetValueOfType5 (p. value) + "sec"; break; case 0x8827: // ISO 40. this. textBox5.Text = GetValueOfType3 (p. value); break; case 0x010E: // image description info. description this. textBox6.Text = GetValueOfType2 (p. value); break; case 0x920a: // the focal length of the photo. this. textBox7.Text = GetValueOfType5A (p. value) + "mm"; break; case 0x829D: // the photo's optical circle Value this. textBox8.Text = GetValueOfType5A (p. value); break; default: break ;}}}
Public string GetValueOfType2 (byte [] B) // read the value of type = 2
{
Return System. Text. Encoding. ASCII. GetString (B );
}
Private static string GetValueOfType3 (byte [] B) // read the value of type = 3
{
If (B. Length! = 2) return "unknow ";
Return Convert. ToUInt16 (B [1] <8 | B [0]). ToString ();
}
Private static string GetValueOfType5 (byte [] B) // read the value of type = 5
{
If (B. Length! = 8) return "unknow ";
UInt32 fm, fz;
Fm = 0;
Fz = 0;
Fz = Convert. ToUInt32 (B [7] <24 | B [6] <16 | B [5] <8 | B [4]);
Fm = Convert. ToUInt32 (B [3] <24 | B [2] <16 | B [1] <8 | B [0]);
Return fm. ToString () + "/" + fz. ToString () + "sec ";
}
Private static string GetValueOfType5A (byte [] B) // obtain the aperture Value
{
If (B. Length! = 8) return "unknow ";
UInt32 fm, fz;
Fm = 0;
Fz = 0;
Fz = Convert. ToUInt32 (B [7] <24 | B [6] <16 | B [5] <8 | B [4]);
Fm = Convert. ToUInt32 (B [3] <24 | B [2] <16 | B [1] <8 | B [0]);
Double temp = (double) fm/fz;
Return (temp). ToString ();
}
Public void FindExifinfo (string filePath) {Image img = Image. fromFile (filePath); PropertyItem [] pt = img. propertyItems; for (int I = 0; I <pt. length; I ++) {PropertyItem p = pt [I]; switch (pt [I]. id) {// device manufacturer 20. case 0x010F: this. textBox1.Text = System. text. ASCIIEncoding. ASCII. getString (pt [I]. value); break; case 0x0110: // device model 25. this. textBox4.Text = GetValueOfType2 (p. value); break; case 0x0132: // photo time 30. this. textBox2.Text = GetValueOfType2 (p. value); break; case 0x829A ://. exposure time this. textBox3.Text = GetValueOfType5 (p. value) + "sec"; break; case 0x8827: // ISO 40. this. textBox5.Text = GetValueOfType3 (p. value); break; case 0x010E: // image description info. description this. textBox6.Text = GetValueOfType2 (p. value); break; case 0x920a: // the focal length of the photo. this. textBox7.Text = GetValueOfType5A (p. value) + "mm"; break; case 0x829D: // the photo's optical circle Value this. textBox8.Text = GetValueOfType5A (p. value); break; default: break ;}}}
Public string GetValueOfType2 (byte [] B) // read the value of type = 2
{
Return System. Text. Encoding. ASCII. GetString (B );
}
Private static string GetValueOfType3 (byte [] B) // read the value of type = 3
{
If (B. Length! = 2) return "unknow ";
Return Convert. ToUInt16 (B [1] <8 | B [0]). ToString ();
}
Private static string GetValueOfType5 (byte [] B) // read the value of type = 5
{
If (B. Length! = 8) return "unknow ";
UInt32 fm, fz;
Fm = 0;
Fz = 0;
Fz = Convert. ToUInt32 (B [7] <24 | B [6] <16 | B [5] <8 | B [4]);
Fm = Convert. ToUInt32 (B [3] <24 | B [2] <16 | B [1] <8 | B [0]);
Return fm. ToString () + "/" + fz. ToString () + "sec ";
}
Private static string GetValueOfType5A (byte [] B) // obtain the aperture Value
{
If (B. Length! = 8) return "unknow ";
UInt32 fm, fz;
Fm = 0;
Fz = 0;
Fz = Convert. ToUInt32 (B [7] <24 | B [6] <16 | B [5] <8 | B [4]);
Fm = Convert. ToUInt32 (B [3] <24 | B [2] <16 | B [1] <8 | B [0]);
Double temp = (double) fm/fz;
Return (temp). ToString ();
}