加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

vb.net 教程 5-7 Bitmap类 3 获得图片信息Exif 3

发布时间:2020-12-16 23:56:23 所属栏目:大数据 来源:网络整理
导读:最后专门谈谈图片中包含的经纬度信息。 PropertyItem.id从0至26都是关于gps信息。详细参看: Property Tags in Numerical Order:https://msdn.microsoft.com/zh-cn/library/ms534418(v=vs.85).aspx 这里仅分析纬度。 纬度的id是2,具体代码: Private Funct
最后专门谈谈图片中包含的经纬度信息。
PropertyItem.id从0至26都是关于gps信息。详细参看:
Property Tags in Numerical Order:https://msdn.microsoft.com/zh-cn/library/ms534418(v=vs.85).aspx
这里仅分析纬度。
纬度的id是2,具体代码:
Private Function getPicInfo(ByVal picFullPath As String) As String
        Dim bmp As New Bitmap(picFullPath)
        Dim strTmp As String = ""
        For Each pro As Imaging.PropertyItem In bmp.PropertyItems
            Select Case pro.Id
                Case 2
                    strTmp = getGpsLatitude(pro.Value)
                Case 1
                    '。。。。。。请自己增加代码。。。。。。
                Case 3
                    '。。。。。。请自己增加代码。。。。。。
                Case 4
                    '。。。。。。请自己增加代码。。。。。。
                    'Case N
                    '。。。。。。请自己增加代码。。。。。。
            End Select
        Next
        Return strTmp
    End Function
增加断点可以看到纬度是一组长度为24的字节值:

具体值为:
前8个字节是度,中间8个字节是分,最后8个字节是秒。
具体getGpsLatitude代码:
Private Function getGpsLatitude(ByVal bteValue() As Byte) As String
        If bteValue.Length <> 24 Then Return "错误的经纬度"

        Dim strTmp As String = ""
        Dim intFirst As Integer
        Dim intSecond As Integer
        intFirst = BitConverter.ToInt32(bteValue,0)
        intSecond = BitConverter.ToInt32(bteValue,4)
        strTmp &= (intFirst / intSecond).ToString & "°"

        intFirst = BitConverter.ToInt32(bteValue,8)
        intSecond = BitConverter.ToInt32(bteValue,12)
        strTmp &= (intFirst / intSecond).ToString & "'"

        intFirst = BitConverter.ToInt32(bteValue,16)
        intSecond = BitConverter.ToInt32(bteValue,20)
        strTmp &= (intFirst / intSecond).ToString & """"

        Return strTmp
    End Function
运行结果:

最后需要说明的是,id=2不一定是北纬,也许是南纬,还要根据id=1的值来判断。相关信息请自己搜索。

由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供参考。

学习更多vb.net知识,请参看vb.net 教程 目录

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读