Reading Exif/GPS data from loaded image

Questions, comments and suggestions concerning VintaSoft Imaging .NET SDK.

Moderator: Alex

Alex
Site Admin
Posts: 1474
Joined: Thu Jul 10, 2008 2:21 pm

Re: Reading Exif/GPS data from loaded image

Post by Alex » Wed Feb 01, 2012 2:34 pm

Please send your JPEG file to support@vintasoft.com - we need to analyze it.

Best regards, Alexander

Alex
Site Admin
Posts: 1474
Joined: Thu Jul 10, 2008 2:21 pm

Re: Reading Exif/GPS data from loaded image

Post by Alex » Thu Feb 02, 2012 8:16 am

Hello,

Here is a code of console application which shows sorted metadata of JPEG file:

Code: Select all

Imports System.IO
Imports Vintasoft.Imaging.Codecs.Tiff
Imports Vintasoft.Imaging.Codecs.Jpeg

Module Module1

    Sub Main()
        Using jpegStream As FileStream = New FileStream("..\..\053.jpg", FileMode.Open, FileAccess.Read)
            Using jpeg As JpegFile = New JpegFile(jpegStream)

                Dim exif As ExifData = jpeg.Page.Exif
                If exif Is Nothing Then
                    Console.WriteLine("JPEG file does not have EXIF data.")
                Else
                    WriteTagsData("EXIF", exif.ExifTags, GetType(ExifTagId))
                    WriteTagsData("GPS", exif.GpsTags, GetType(GpsTagId))
                End If

            End Using
        End Using

        Console.WriteLine("Press any key to continue...")
        Console.ReadKey()
    End Sub

    Private Sub WriteTagsData(ByRef tagsName As String, ByRef tags As TiffTagCollection, ByRef tagIdEnumType As Type)
        If tags.Count = 0 Then
            Console.WriteLine(String.Format("No {0} data.", tagsName))
        Else
            Console.WriteLine(String.Format("{0} data [{1}]:", tagsName, tags.Count))
            Dim tag As TiffTag
            Dim tagData As Object
            Dim tagDataAsArray As Array
            Dim tagDataAsString As String
            ' for each tag in tag collection
            For i = 0 To tags.Count - 1
                ' get tag
                tag = tags(i)

                ' get tag data
                tagData = tag.Data
                ' if tag data is array
                If IsArray(tagData) Then

                    tagDataAsString = "[ "
                    tagDataAsArray = CType(tagData, Array)
                    For j = 0 To tagDataAsArray.Length - 1
                        tagDataAsString = tagDataAsString + tagDataAsArray(j).ToString + "; "
                    Next
                    tagDataAsString = tagDataAsString + "]"

                    ' if tag data is NOT array
                Else
                    tagDataAsString = tagData.ToString()
                End If

                ' add information about tag to textbox
                Console.WriteLine(String.Format("- Name={0}, Id={1}, Type={2}, Data={3}", tag.GetName(tagIdEnumType), tag.Id, tag.Type, tagDataAsString))
            Next
        End If
        Console.WriteLine()
    End Sub

End Module
Best regards, Alexander

js95007
Posts: 7
Joined: Wed Feb 01, 2012 9:28 am

Re: Reading Exif/GPS data from loaded image

Post by js95007 » Fri Feb 03, 2012 7:57 am

Hey Alex, thanks for that latest code, however for my purposes it needs to be in a Windows Form Application.
The previous code worked well in that sense, so all I need is a way to extract the longitude and latitude themselves and display in a textbox, much like what communi needed on Page 1 of this thread.
The latitude for example is displayed like this -
Name=GPSLatitude, Id=2, Type=Rational, Data=[ 35 / 1; 43 / 1; 475 / 100;
where as the real latitude for the picture is 35 43 4.75
If there was a way to have a textbox for longitude reading that and one for latitude doing the same, that would be great.

Thanks again

Alex
Site Admin
Posts: 1474
Joined: Thu Jul 10, 2008 2:21 pm

Re: Reading Exif/GPS data from loaded image

Post by Alex » Fri Feb 03, 2012 10:28 am

Hello,

Сode from previous post shows you how to get information about GPS metadata from JPEG file, further coding is your work as a programmer. :-)

Please contact our sales team at sales@vintasoft.com if you need custom programming.

Best regards, Alexander

js95007
Posts: 7
Joined: Wed Feb 01, 2012 9:28 am

Re: Reading Exif/GPS data from loaded image

Post by js95007 » Fri Feb 03, 2012 10:52 am

Fair enough, I think I've cracked it anyway :D
Thanks again for all your help

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests