• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C#如何获取照片中Exif信息里GPS信息与经纬度数

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

 

C# 如何获取照片中Exif信息里GPS信息与经纬度数

 
10
如题..
补充: 希望能给出详细点代码.我在网上找的代码都无法准确算出经纬度信息.
补充:

附加段相关代码

 

            #region
            //載入圖片   
            Image objImage = Image.FromFile("E:\\Pictures\\20080512131.jpg");
            //取得所有的屬性(以PropertyId做排序)   
            var propertyItems = objImage.PropertyItems.OrderBy(x => x.Id);
            //暫訂緯度為N(北緯)   
            char chrGPSLatitudeRef = 'N';
            //暫訂經度為E(東經)   
            char chrGPSLongitudeRef = 'E';
            foreach (PropertyItem objItem in propertyItems)
            {
                //只取Id範圍為0x0000到0x001e   
                if (objItem.Id >= 0x0000 && objItem.Id <= 0x001e)
                {
                    objItem.Id = 0x0002;
                    switch (objItem.Id)
                    {
                        case 0x0000:
                            var query = from tmpb in objItem.Value select tmpb.ToString();
                            string sreVersion = string.Join(".", query.ToArray());
                            richTextBox1.Text = sreVersion;
                            break;
                        case 0x0001:
                            chrGPSLatitudeRef = BitConverter.ToChar(objItem.Value, 0);
                            break;
                        case 0x0002:
                            if (objItem.Value.Length == 24)
                            {
                                //degrees(將byte[0]~byte[3]轉成uint, 除以byte[4]~byte[7]轉成的uint)   
                                double d = BitConverter.ToUInt32(objItem.Value, 0) * 1.0d / BitConverter.ToUInt32(objItem.Value, 4);
                                //minutes(將byte[8]~byte[11]轉成uint, 除以byte[12]~byte[15]轉成的uint)   
                                double m = BitConverter.ToUInt32(objItem.Value, 8) * 1.0d / BitConverter.ToUInt32(objItem.Value, 12);
                                //seconds(將byte[16]~byte[19]轉成uint, 除以byte[20]~byte[23]轉成的uint)   
                                double s = BitConverter.ToUInt32(objItem.Value, 16) * 1.0d / BitConverter.ToUInt32(objItem.Value, 20);
                                //計算緯度的數值, 如果是南緯, 要乘上(-1)   
                                double dblGPSLatitude = (((s / 60 + m) / 60) + d) * (chrGPSLatitudeRef.Equals('N') ? 1 : -1);
                                string strLatitude = string.Format("{0:#} deg {1:#}' {2:#.00}\" {3}", d, m, s, chrGPSLatitudeRef);
                            }
                            break;
                        case 0x0003:
                            //透過BitConverter, 將Value轉成Char('E' / 'W')   
                            //此值在後續的Longitude計算上會用到   
                            chrGPSLongitudeRef = BitConverter.ToChar(objItem.Value, 0);
                            break;
                        case 0x0004:
                            if (objItem.Value.Length == 24)
                            {
                                //degrees(將byte[0]~byte[3]轉成uint, 除以byte[4]~byte[7]轉成的uint)   
                                double d = BitConverter.ToUInt32(objItem.Value, 0) * 1.0d / BitConverter.ToUInt32(objItem.Value, 4);
                                //minutes(將byte[8]~byte[11]轉成uint, 除以byte[12]~byte[15]轉成的uint)   
                                double m = BitConverter.ToUInt32(objItem.Value, 8) * 1.0d / BitConverter.ToUInt32(objItem.Value, 12);
                                //seconds(將byte[16]~byte[19]轉成uint, 除以byte[20]~byte[23]轉成的uint)   
                                double s = BitConverter.ToUInt32(objItem.Value, 16) * 1.0d / BitConverter.ToUInt32(objItem.Value, 20);
                                //計算緯度的數值, 如果是西經, 要乘上(-1)   
                                double dblGPSLongitude = (((s / 60 + m) / 60) + d) * (chrGPSLongitudeRef.Equals('E') ? 1 : -1);
                                Console.WriteLine("{0:#} deg {1:#}' {2:#.00}\" {3}", d, m, s, chrGPSLongitudeRef);  
                            }
                            break;
                        case 0x0005:
                            string strAltitude = BitConverter.ToBoolean(objItem.Value, 0) ? "0" : "1";
                            break;
                        case 0x0006:
                            if (objItem.Value.Length == 8)
                            {
                                //將byte[0]~byte[3]轉成uint, 除以byte[4]~byte[7]轉成的uint   
                                double dblAltitude = BitConverter.ToUInt32(objItem.Value, 0) * 1.0d / BitConverter.ToUInt32(objItem.Value, 4);
                            }
                            break;  
                    }
                }
            }
            #endregion


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++基于EasyX制作贪吃蛇游戏(三)第二版文档发布时间:2022-07-13
下一篇:
[经验栈]C#中几种定时器(timer)的区别发布时间:2022-07-13
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap