C # exif information

Source: Internet
Author: User
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 ();

 

}

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.