C# exif 資訊

來源:互聯網
上載者:User
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();

 

        }

 

 

 


 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.