欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

c# 獲取照片的經(jīng)緯度和時間的示例代碼

 更新時間:2020年11月30日 10:52:34   作者:gisoracle  
這篇文章主要介紹了c# 獲取照片的經(jīng)緯度和時間的示例代碼,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下
public List<string> GetXYFromPic(String jpgPath)
    {
      List<string> sXY = new List<string>();
      try
      {
        //載入圖片  
        Image objImage = Image.FromFile(jpgPath);
        //取得所有的屬性(以PropertyId做排序)  
        var propertyItems = objImage.PropertyItems.OrderBy(x => x.Id);
        foreach (PropertyItem objItem in propertyItems)
        {
          //只取Id范圍為0x0000到0x001e
          if (objItem.Id >= 0x0000 && objItem.Id <= 0x001e)
          {
            switch (objItem.Id)
            {
              case 0x0002://設(shè)置緯度
                if (objItem.Value.Length == 24)
                {
                  //degrees(將byte[0]~byte[3]轉(zhuǎn)成uint, 除以byte[4]~byte[7]轉(zhuǎn)成的uint)  
                  double d = BitConverter.ToUInt32(objItem.Value, 0) * 1.0d / BitConverter.ToUInt32(objItem.Value, 4);
                  //minutes(將byte[8]~byte[11]轉(zhuǎn)成uint, 除以byte[12]~byte[15]轉(zhuǎn)成的uint)  
                  double m = BitConverter.ToUInt32(objItem.Value, 8) * 1.0d / BitConverter.ToUInt32(objItem.Value, 12);
                  //seconds(將byte[16]~byte[19]轉(zhuǎn)成uint, 除以byte[20]~byte[23]轉(zhuǎn)成的uint)  
                  double s = BitConverter.ToUInt32(objItem.Value, 16) * 1.0d / BitConverter.ToUInt32(objItem.Value, 20);
                  double dblGPSLatitude = (((s / 60 + m) / 60) + d);
 
                  sXY.Add(dblGPSLatitude.ToString("0.00000000"));
                }
                break;
              case 0x0004: //設(shè)置經(jīng)度
                if (objItem.Value.Length == 24)
                {
                  //degrees(將byte[0]~byte[3]轉(zhuǎn)成uint, 除以byte[4]~byte[7]轉(zhuǎn)成的uint)  
                  double d = BitConverter.ToUInt32(objItem.Value, 0) * 1.0d / BitConverter.ToUInt32(objItem.Value, 4);
                  //minutes(將byte[8]~byte[11]轉(zhuǎn)成uint, 除以byte[12]~byte[15]轉(zhuǎn)成的uint)  
                  double m = BitConverter.ToUInt32(objItem.Value, 8) * 1.0d / BitConverter.ToUInt32(objItem.Value, 12);
                  //seconds(將byte[16]~byte[19]轉(zhuǎn)成uint, 除以byte[20]~byte[23]轉(zhuǎn)成的uint)  
                  double s = BitConverter.ToUInt32(objItem.Value, 16) * 1.0d / BitConverter.ToUInt32(objItem.Value, 20);
                  double dblGPSLongitude = (((s / 60 + m) / 60) + d);
                  sXY.Add(dblGPSLongitude.ToString("0.00000000"));
                }
                break;
            }
          }
          if (objItem.Id == 0x9003 || objItem.Id == 0x0132)//Id為0x9003表示拍照的時間,0x0132 最后更新時間
          {
            var propItemValue = objItem.Value;
            var dateTimeStr = System.Text.Encoding.ASCII.GetString(propItemValue).Trim('\0');
            var dt = DateTime.ParseExact(dateTimeStr, "yyyy:MM:dd HH:mm:ss", CultureInfo.InvariantCulture);
            sXY.Add(dt.ToString());//.ToShortDateString()
          }
        }
 
        objImage.Dispose();
        return sXY;
 
      }
      catch (Exception ex)
      {
        //MessageManager.Show(jpgPath + "該圖片文件損壞");
        //listErrorMessage.Add(jpgPath + "該照片由于照片損壞,因此無法進行導入。");
        return sXY;
      }
 
    }

以上就是c# 獲取照片的經(jīng)緯度和時間的示例代碼的詳細內(nèi)容,更多關(guān)于c# 獲取照片的經(jīng)緯度和時間的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論