B4A Library JpegUtils library gives access to Exif data

Erel

Administrator
Staff member
Licensed User
Here (make sure to test the results):
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim s As String = "56/1,16973828/65539,393216/1795N "
   Dim m As Matcher = Regex.Matcher("(\d+/\d+),(\d+/\d+),(\d+/\d+)", s)
   If m.Find Then
      Dim lat As Double
      lat = FractionToDouble(m.Group(1))
      lat = lat + FractionToDouble(m.Group(2)) / 60
      lat = lat + FractionToDouble(m.Group(3)) / 3600
      Log(lat)
   End If
End Sub

Private Sub FractionToDouble(frac As String) As Double
   Dim n() As String = Regex.Split("/", frac)
   Return n(0) / n(1)
End Sub
Please start a new thread for the second question.
 

corvo

Member
Licensed User
Thank you Erel, but it don't works, the result of your code is 60.377(and more), but the correct latitude is 38.22741586714989, and your code don't work also whit longitude (but the format of the longitude is different from exiftag "858861618/976629818.939537202/1E"). I put the pics in this post, maibe you can find some problem in the image or in the code (the pic is in a .rar cause the siza was too big for the forum limit)
 

corvo

Member
Licensed User
Erel, if i use the function of the phone "find the place of the pic" google maps put a marker on my home.....
 

agraham

Expert
Licensed User
getLatLong

Method

Stores the latitude and longitude value in a float array. The first element is the latitude,
and the second element is the longitude.
Returns false if the Exif tags are not available.

Returns : Boolean

getLatLong(output As Float())
B4X:
Dim LL(2) As Float
exif.getLatLong(LL)
Msgbox("Latitude = " & LL(0), "Latitude")
 

agraham

Expert
Licensed User
There seems to be something odd about the format that the camera is writing.

An online EXIF viewer gives this
Camera
SAMSUNG GT-I8190N

GPS Position
60.316476 degrees N, 1.813130 degrees E

Opening the image in Google Earth shows
Lat: 60.3166727, Lon: 1.9337032
 

gadgetmonster

Active Member
Licensed User
Saving Exif Latitude and Longitude

Hi,

I am using this wonderful library to get lat and long data from photos. This works a treat. My problem is saving it back out. I can save the date and time fine, its just saving latitude and longitude.

If I have two variables lat = 51.329444 and lon = 1.1839 for example, I do the following:

B4X:
exif.Initialize(File.DirRootExternal & "/app/", "photo.jpg")
exif.setAttribute(exif.TAG_GPS_LATITUDE, lat)
exif.setAttribute(exif.TAG_GPS_LONGITUDE, lon)
exif.setAttribute(exif.TAG_DATETIME,  exifDTM)
exif.saveAttributes
The date is fine but how should the latitude and longitude be formatted?

The above does not work as I can't load the coordinates back in. I have also tried hard coding to something like 59; 19; 46 but that doesn't work either.

Any ideas?
 

gadgetmonster

Active Member
Licensed User
See my post #20 in this thread. Looks like you need a string of three rational numbers separated by commas.
I have tried a test using:

B4X:
exif.setAttribute(exif.TAG_GPS_LATITUDE, "51/1,19/1,46/1")
exif.setAttribute(exif.TAG_GPS_LONGITUDE, "1/1,5/5,5/5")
and

B4X:
exif.setAttribute(exif.TAG_GPS_LATITUDE, "51,19,46")
exif.setAttribute(exif.TAG_GPS_LONGITUDE, "1,5,5")
but this still doesn't work.

Am I missing something here?
 

gadgetmonster

Active Member
Licensed User
A little bit of a development.

I have tested the photo I am saving out and the exif data is saved. I used a desktop app that positions photos on a map and it is spot on. This proves that the exif data is being written out and correctly.

The problem therefore is when I read it back in. I am using:

B4X:
exif.Initialize(File.DirRootExternal & "/app/", "photo.jpg")
Dim output(2) as Float
if exif.getLatLong(output) = True Then
    lat = output(0)
    lon = output(1)
else
    lat = ""
    lon = ""
end if
exif.getLatLong(output) always = false
 

daemon

Active Member
Licensed User
Hi,

Can this library work on Byte() instead of a file?
I want to use this library on a picture taken from camera, without storing the data to a file. I want to store after updating EXIF data.

Thanks!
 
Top