Android Question Big Exif data in JPEG

AlpVir

Well-Known Member
Licensed User
Longtime User
I have some files JPG that they have inside the EXIF data rather full-bodied (ca 8 KB) I entered through a VB6 program I created and which uses the library FreeImage.
With B4A are able to read these data but not to write.
Andrew Graham JpegUtils library is limited to several small data related to GPS (latitude, longitude, etc.) and images (ISO, image length, etc.).
This unfortunately is not enough !
But I would like to write in the "Comment" EXIF data of a JPG file these 8KB of ASCII characters.
Some idea ?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Check this API: https://developer.android.com/reference/android/media/ExifInterface.html
If it supports the features that you are looking for then it is simple to call it with JavaObject.

B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim Exif As JavaObject
   Exif.InitializeNewInstance("android.media.ExifInterface", Array(File.Combine(File.DirRootExternal, "13.jpg")))
   Exif.RunMethod("setAttribute", Array(ExifConst("TAG_ARTIST"), "John Due"))
   'set more attributes here...
   Exif.RunMethod("saveAttributes", Null)
End Sub

Private Sub ExifConst(tag As String) As String
   Dim jo As JavaObject
   Return jo.InitializeStatic("android.media.ExifInterface").GetField(tag)
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
But I would like to write in the "Comment" EXIF data of a JPG file these 8KB of ASCII characters.
Can you give an example of such an jpg-file? Upload the file please.
I have a wrap for the Android Exif-Interface and i would like to try it on a Android 6 (Api 24) Device...
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
@Erel
Thank you ! I shall examine your suggestion.

@DonManfred:
You can download the 4 high-definition panoramas from the 4 following link :
4516901 http://www.lalpinistavirtuale.it/panorami2/HD_Aiera.JPG (without EXIF data)
1696348 http://www.lalpinistavirtuale.it/panorami2/HD_CimaAgnel.jpg (with EXIF data)
2725814 http://www.lalpinistavirtuale.it/panorami2/HD_RoccaAbisso.jpg (with EXIF data)
2100519 http://www.lalpinistavirtuale.it/panorami2/HD_Vanclava2.JPG (with EXIF data)

You can download the 226 (!) low-definition panoramas from the following links:
http://www.lalpinistavirtuale.it/panorami/Aiera.JPG
http://www.lalpinistavirtuale.it/panorami/CimaAgnel.jpg
http://www.lalpinistavirtuale.it/panorami/RoccaAbisso.jpg
http://www.lalpinistavirtuale.it/panorami/Vanclava2.JPG
etc. etc.

The app "360 ALP PANORAMI" (currently being finalized and poorly translated into English) manages 226 low-resolution panoramas and 4 high-definition panoramas above.
Can be downloaded from Google Play (https://play.google.com/store/apps/details?id=alpvir.panorami)
The 226 panoramas can be viewed using a PC to link :
http://www.lalpinistavirtuale.it/panorami

The EXIF data contained in HD_RoccaAbisso.jpg views are marked in red in the attached image.
 

Attachments

  • RoccaAbisso_exif.jpg
    RoccaAbisso_exif.jpg
    286.8 KB · Views: 406
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
The EXIF data contained in HD_RoccaAbisso.jpg views are marked in red in the attached image.

do you mean this data?
Nome=HD_RoccaAbisso@ID=9557|9128|9129|911|9154|1024|708|1004|737|772|854|9763|12760|852|824|1005|9765|908|9171|851|9781|9782|12801|775|1023|12713|9779|752|9299|774|9558|9345|9569|9344|10036|9783|12743@Colore=0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0@Posizione=48|5|28|27|15|34|39|73|32|21|18|-1|56|22|2|18|23|52|9|6|18|-1|6|46|42|55|37|3|21|45|17|6|2|18|48|56|16@TotID=37@OffsetX=1937@Distanza max=71@Distanza min=0@Versione programma=1.5.9@Tipo=R@Latitudine=44.1436055456434@Longitudine=7.50379202674208@RecordID=9991@Altezza=2755@Nome centro=ABISSO (ROCCA DELL'A.@Note=@Toponimi=AIERA (MONTE)#2713 m Dist=8,9 Km|ARGENTERA (CIMA NORD)#3286 m Dist=16,4 Km|ARGENTERA (CIMA SUD)#3297 m Dist=16,3 Km|BASTIONE (IL)#3047 m Dist=15,8 Km|BEGO (MONTE)#2872 m Dist=8,9 Km|BERTRAND (MONTE)#2482 m Dist=13,9 Km|BESIMAUDA (MONTE)#2230 m Dist=16,2 Km|BESIMAUDA (PILIER CENTRALE)#2258 m Dist=15,3 Km|BROCAN (CIMA DI)#3056 m Dist=15,7 Km|CARS (CIMA)#2218 m Dist=18,0 Km|CIAUDON (TESTA)#2387 m Dist=10,8 Km|CORNE DE BOUC (POINTE DE LA)#2414 m Dist=10,7 Km|COSSATO (CIME)#2876 m Dist=6,7 Km|COSTA ROSSA (BRIC)#2403 m Dist=14,2 Km|FASCIA (CIMA DELLA)#2491 m Dist=11,0 Km|FRANCIA (CIMA DI)#1427 m Dist=16,2 Km|GARLENDA (CIMA)#2142 m Dist=22,5 Km|GELAS (MONTE)#3143 m Dist=9,8 Km|GRAND CAPELET (MONT DU)#2935 m Dist=9,5 Km|MARGUAREIS (PUNTA)#2652 m Dist=14,8 Km|MARTA (BALCON DI)#2122 m Dist=18,5 Km|MARTA (CIME DE)#2136 m Dist=18,5 Km|MATTO (MONTE)#3097 m Dist=21,8 Km|MIRAUDA (PUNTA)#2155 m Dist=12,9 Km|MISSUN (CIMA)#2356 m Dist=16,1 Km|NASTA (CIMA DI)#3108 m Dist=16,0 Km|NAUQUE (CIME DE LA)#2207 m Dist=10,2 Km|PAGANINI (CIMA)#3051 m Dist=16,0 Km|PEIRAFICA (PUNTA DI)#2626 m Dist=1,3 Km|PITTE' (CIMA)#2172 m Dist=13,4 Km|RUA (PUNTA DELLA)#2780 m Dist=7,9 Km|SAINTE MARIE (MONTE)#2740 m Dist=6,4 Km|SALVATORE (PUNTA SAN)#2410 m Dist=10,8 Km|STELLA (MONTE)# Dist=16,3 Km|TENDA (POLVERIERA)#0 m Dist=5,1 Km|TORRAGGIO (MONTE)#1871 m Dist=22,1 Km|VALLETTA (CIMA DELLA)#2808 m Dist=4,6 Km@XTopoLinea=13969|13192|13149|12848|10187|5966|3132|3156|12753|4392|4801|9225|11677|3240|4536|2448|6451|12080|10649|4981|7625|7424|13589|3861|6197|12965|8683|13023|11177|3483|13899|10448|4673|13236|5012|7764|12665@XTopoVero=14011|13218|13177|12886|10199|5947|3128|3153|12796|4386|4806|9226|11650|3234|4546|2448|6436|12115|10670|4969|7614|7410|13616|3852|6180|12957|8679|13012|9999|3479|13946|10463|4670|13261|5014|7741|9999@YTopoVero=285|215|215|251|255|271|295|294|248|283|248|335|209|278|255|417|297|207|250|230|325|317|250|321|283|245|383|241|10006|315|267|299|271|216|329|328|10006@LargImmagine=14245@BordoSxFotoNormale=0@BordoDxFotoNormale=0@

And this data you want to change?
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
Exactly!
This code works perfectly, but I have yet to test it to store a few KB of data.
B4X:
Dim Exif As JavaObject
    Exif.InitializeNewInstance("android.media.ExifInterface",  Array(File.Combine(File.DirRootExternal, Main.NomeFileCompleto & ".jpg")))
    Exif.RunMethod("setAttribute", Array("UserComment", "test A test B  test C"))
    Exif.RunMethod("saveAttributes", Null)
Have you tried the app ?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
, but I have yet to test it to store a few KB of data.
So i´ll try to add some data to the UserComment i got and write it back again... Let´s see what happen ;)
Have you tried the app ?
No, i was using my exif wrapper to read the data
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
i tried to double the usercomment on each run... run the app a few times... Last log

Length of UserComment read: 21784
Note it started with the data above...

B4X:
    Dim filePath As String
    filePath = File.Combine(rp.GetSafeDirDefaultExternal("pics"), "hd_roccaabisso.jpg")
    exif.Initialize("",filePath)
    Dim m As Map = exif.GetAllAttributes
    Log(m)
    Log(m.Get("UserComment"))

    Dim usercomment As String = m.Get("UserComment")

    Log("Length of UserComment read: "&usercomment.Length)

    usercomment = usercomment&usercomment
    exif.setAttribute("UserComment",usercomment)
    exif.saveAttributes

You can download the edited image here: https://www.dropbox.com/s/azjx30llk0uzq8z/hd_roccaabisso.jpg?dl=0

Find the lib i used attached.
 

Attachments

  • ExifInterface4aV1.26.zip
    4.3 KB · Views: 356
Last edited:
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
With this code I read perfectly the UserComment field :
B4X:
Dim DatiExif        As StringBuilder
    Dim bu(8000)        As Byte
    DatiExif.Initialize
    Dim InputStream1     As InputStream
    Try
        InputStream1 = File.OpenInput (File.DirRootExternal,Main.NomeFileCompleto)
        count = InputStream1.ReadBytes (bu,0,8000)
        InputStream1.Close
    Catch
        Msgbox ("Il file " & Main.NomeFileCompleto & " è corrotto" & CRLF & "Bisogna cancellarlo","ERRORE")
        BB=File.Delete(File.DirRootExternal,Main.NomeFilecompleto)
        ExitApplication
    End Try    
    For i=0 To 7999
        DatiExif.Append (Chr(bu(i)))
    Next
    Riga=DatiExif.ToString


Basically would produce the same result of your m.Get ("UserComment")
I downloaded your library but there is still something wrong.
LogColor produces a "null"

B4X:
Dim filePath As String
    filePath = File.Combine(File.DirRootExternal, Main.NomeFileCompleto)
    Log(filePath)     ' /storage/emulated/0/PANORAMI/ROCCAABISSO.jpg
    exif.Initialize("",filePath)
    Dim m As Map = exif.GetAllAttributes
    LogColor(m.Get("UserComment"),Colors.red )

It can be a matter of Android version (I have the 5) ?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I just discovered that there is a Exif interface in the Support library now...
https://android-developers.googleblog.com/

With the release of the 25.1.0 Support Library, there's a new entry in the family: the ExifInterface Support Library. With significant improvements introduced in Android 7.1 to the framework's ExifInterface, it only made sense to make those available to all API 9+ devices via the Support Library's ExifInterface.

The basics are still the same: the ability to read and write Exif tags embedded within image files: now with 140 different attributes (almost 100 of them new to Android 7.1/this Support Library!) including information about the camera itself, the camera settings, orientation, and GPS coordinates.

I´ve changed my lib to use THIS exifinterface now....

Try again with this lib on your device.
 

Attachments

  • ExifInterface4aV1.3.zip
    4.9 KB · Views: 344
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
The two codes below produce the same positive result :
B4X:
Dim Exif As JavaObject
        Exif.InitializeNewInstance("android.media.ExifInterface",  Array(File.Combine(File.DirRootExternal, Main.NomeFileCompleto)))
        Exif.RunMethod("setAttribute", Array("UserComment",sb.ToString))
        Exif.RunMethod("saveAttributes", Null)

B4X:
    Dim filePath As String
    filePath = File.Combine(File.DirRootExternal,Main.NomeFileCompleto)
    Exif.Initialize("",filePath)
    Exif.setAttribute("UserComment",sb.ToString)
    Exif.saveAttributes

Thanks to the two authors (Erel and Don Manfred) !
But I can not explain why the result is positive despite having a smartphone with Android 5.0 and using the API 22 (non Android 7 and API 24).
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
But I can not explain why the result is positive despite having a smartphone with Android 5.0 and using the API 22 (non Android 7 and API 24).
if you are using V1.3 (using the support exifinterface) then this is the solution.

Due to the google-blog-post i mentioned i guess the suggested method is to use the support exifinterface as it is compatible down to api 9.
 
Upvote 0
Top