Get EXIF data from a JPEG

I spent my weekend banging my head on this one.  I learned a lot about EXIF data, but apparently not enough.

I'm trying to get the EXIF data from JPEG photos.  Specifically, the GPS information (when the GPS setting has been enabled on my camera).  I found a vb class that helped a lot, but is too long to post here.  Here is a link to it:

http://sourceforge.net/projects/exifclass/

Basically, what I've been able to do (in Excel) is iterate through the EXIF data and print it in cells.  So I have something like this for the first few pieces of information:

 

 

FileDateTime: 2011:03:13 15:40:46
htmlWidth: 2592
htmlHeight: 1936
ApertureFNumber: 14/5
Make: Apple
Model: iPhone 4
Orientation: 1
XResolution: 72/1
YResolution: 72/1
ResolutionUnit: 2
Software: 4.2.1
YCbCrPositioning: 1
GPSIFDPointer: 574

 

What's frustrated me most is my lack of understanding of hexadecimals and how to actually use them.   The class that I linked to makes it pretty easy to show the EXIF data.  For example, to get the GPSIFDPointer (whose hex value is &H8825&), you do this:

"img.Tag(GPSIFDPointer)" and that outputs "574"

In the class, a public enum is created:

Public Enum EXIF_TAG

...EXIF data...

GPSIFDPointer = &H8825&

...more EXIF data...

End Enum

But now follow this link:

http://www.awaresystems.be/imaging/tiff/tifftags/privateifd/gps.html

We see that the GPSLatitude data is 0x0002 (or &O2&, I think).  Well, I've exhausted myself trying to figure out how to make that work in the class.  I tried just adding a line underneath the "GPSIFDPointer = &H8825&" that says "GPSLatitude = &O2&" and then outputting something like Cells(1,1) = img.Tag(GPSLatitude) but it returns nothing, and other things I've tried have been unsuccessful as well.

My ultimate goal in all of this is to be able to make images appear in MicroStation in their correct geolocation.  I know this can be done with TIFFs but to make the application I'm working on as user friendly as possible I'd like to get this to work with a typical geotagged JPEG from a camera.  I also tried getting the EXIF data through some of the raster classes in MicroStation's VBA but was unsuccessful.  If it's possible to do it through MicroStation's VBA I'd rather do it that way.

 

Thanks

  • Hi,

    I don't know anything about the stuff you're asking about.   As far as Hexidecimal, here's a one second run down:
    In Decimal each digit is multiplied by 10 raised to the n- degree, based on position, let me explain:

    Example number = 2548 is equal to
    8 times 10 raised to the 0 power  = 8 * 10^0 = 8*1 = 8
    4 times 10 raised to the 1 power = 4 * 10^1 = 4*10 = 40
    5 --> 5 * 10^2 = 5*100 = 500
    2--> 2 * 10^4 = 2*1000 = 2000
    And the final result is 8 + 40 + 500 + 2000 = 2548

    With Hex you do the same thing except with the base being 16 instead of 10.  Also, we don't have 16 numbers, so we have to use letters to represent numbers:
    0 = 0
    1 = 1
    ...
    9 = 9
    A = 10
    B = 11
    C = 12
    D = 13
    E = 14
    F = 15

    So using an example number "2F5A" we do
    A--> 10 * 16^0 = 10*1 = 10
    5--> 5 * 16^1 = 5*16 = 80
    F--> 15 * 16^2 = 15*256 = 3840
    2--> 2 * 16^3 = 2*4096 = 8192
    So the final number is 10+80+3840+8192 = 12,122

    (I assume that you know that "raised to a number" means multiplied that number of times--16^3 = 16*16*16 = 4096.  Also anything ^0  is equal to one.)

    I have no idea if this helps, but it may.

    --Robert

  • alternate_exterior said:
    what I've been able to do (in Excel) is iterate through the EXIF data and print it in cells

    Your question apprears unrelated to MicroStation, but more related to image handling and Excel.

    Why not look in more appropriate places on the web? There are plenty of sites that deal with Excel VBA and plenty more that deal with images. There are a few mentioned on our links page, but that list is by no means exhaustive.

    Robert's given a brief summary of hexadecimal. It's just a way of writing numbers that's convenient when dealing with 4-bit, 8-bit, 16-bit etc. computer arithmetic.

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

  • Thank you both for your suggestions.

    I know I talked about a lot of non-MicroStation related things but the gist of it is I'm trying to import JPEG's with coordinate data into a MicroStation file so that they appear in their geolocation.  Can MicroStation VBA retrieve that sort of data from an image, say, with any of the Raster classes or members?

  • Raster.GeoReferenceInformation

    The VBA Raster object has the GeoReferenceInformation property. That might do what you ask, but it's not documented. I created a subroutine to see what IntelliSense reveals …

    Sub TestRasterGeo(ByVal oRaster As raster)
      Dim geo As GeoReferenceInformation
      Set geo = oRaster.GeoReferenceInformation
      geo.origin
      geo.Extent
      geo.RotationAboutZ
    End Sub

    Because of the lack of documentation, I have no idea whether those properties can be used with a JPEG image. You'll need to log a support request with Bentley Systems.

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

  • I gave it a shot but it only gave me the location of the raster in the design file and not any kind of latitude/longitude information from where I was standing when I took the photo.

    Thanks anyway!

  • Hi,

    The EXIF tags are currently not used by MicroStation. So there is no way that you could obtain that information from it.

    The GPSIFDPointer indicates the position of the EXIF GPS directory.

    The EXIF tags are stored in TIFF file which is embedded in the JPEG file. A TIFF file is composed of a main directory and optionally other sub-directory.

    When you call img.Tag(GPSIFDPointer) you are querying the main directory for the tag GPSIFDPointer. The value returns (i.e. : 574) indicate the position (i.e. : the absolute file postion in bytes) of the sub-directory EXIF GPS containing the GPSLatitude tag among other tags.

    I know nothing about the the VB class that you are using but you probably wil need to create or tell the img to switch directory and go to the one located at 574. After the switch calling img.Tag(GPSLatitude) should give you what you want.

    Thanks,

    Mathieu