C# exif 信息
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) { // 设备制造商 20. case 0x010F: this.textBox1.Text = System.Text.ASCIIEncoding.ASCII.GetString(pt[i].Value); break; case 0x0110: // 设备型号 25. this.textBox4.Text = GetValueOfType2(p.Value); break; case 0x0132: // 拍照时间 30. this.textBox2.Text = GetValueOfType2(p.Value); break; case 0x829A: // .曝光时间 this.textBox3.Text = GetValueOfType5(p.Value)+" sec"; break; case 0x8827: // ISO 40. this.textBox5.Text = GetValueOfType3(p.Value); break; case 0x010E: // 图像说明info.description this.textBox6.Text = GetValueOfType2(p.Value); break; case 0x920a: //相片的焦距 this.textBox7.Text = GetValueOfType5A(p.Value) + " mm"; break; case 0x829D: //相片的光圈值 this.textBox8.Text = GetValueOfType5A(p.Value); break; default: break; } } }
public string GetValueOfType2(byte[] b)// 对type=2 的value值进行读取
{
return System.Text.Encoding.ASCII.GetString(b);
}
private static string GetValueOfType3(byte[] b) //对type=3 的value值进行读取
{
if (b.Length != 2) return "unknow";
return Convert.ToUInt16(b[1] << 8 | b[0]).ToString();
}
private static string GetValueOfType5(byte[] b) //对type=5 的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]);
return fm.ToString() + "/" + fz.ToString()+" sec";
}
private static string GetValueOfType5A(byte[] b)//获取光圈的值
{
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();
}