B4A Library JpegUtils library gives access to Exif data

bluedude

Well-Known Member
Licensed User
That sounds awesome, could mean I can write GPS stuff to the images taken with the camera.
 

praetor100

New Member
Hi agraham,

I'm also would like to save descriptions into jpg exif data. Please could you add this meta tag in your library?

Thank you and best regards
praetor
 

wheretheidivides

Active Member
Licensed User
I did find this link which goes over exif data. Such as the numbers for orientation and such. Listed below are some numbers returned by this library in case you wondered what they were. These are the tags like: x = exif.getAttribute(exif.TAG_FLASH). X is a string that will hold the returned info. the rest that are currently supported by the library have no variable info. this really needs to be with docs so people can find easily.

EXIF Tags
http://developer.android.com/reference/android/media/ExifInterface.html#TAG_GPS_ALTITUDE
==============================
orientation:
0 = unassigned
1 = Horizontal (normal)
2 = Mirror horizontal
3 = Rotate 180
4 = Mirror vertical
5 = Mirror horizontal and rotate 270 CW
6 = Rotate 90 CW
7 = Mirror horizontal and rotate 90 CW
8 = Rotate 270 CW
======================
white balance
0 = Auto
1 = Manual
=========================
GPSLatitudeRef
'N' = North
'S' = South
======================
GPSLongitudeRef
'E' = East
'W' = West
=======================
GPSAltitudeRef
0 = Above Sea Level
1 = Below Sea Level
=====================
GPSProcessingMethod
(values of "GPS", "CELLID", "WLAN" or "MANUAL" by the EXIF spec.)
=====================
GPSDateStamp
(when writing, time is stripped off if present, after adjusting date/time to UTC if time includes a timezone. Format is YYYY:mm:dd)
===========================
ApertureValue
(displayed as an F number, but stored as an APEX value)
================================
GPSTimeStamp
(when writing, date is stripped off if present, and time is adjusted to UTC if it includes a timezone)
============================
"GPSAltitude"
The altitude (in meters) based on the reference in TAG_GPS_ALTITUDE_REF. Type is rational.
1 Meter = 3.28083989501312 Feet
1 mile = 5280 feet
==============================
"GPSLatitude"
String. Format is "num1/denom1,num2/denom2,num3/denom3".
===========================
"GPSLongitude"
String. Format is "num1/denom1,num2/denom2,num3/denom3".

==========================
flash:
Indicates the status of flash when the image was shot.

Bit 0 indicates the flash firing status, bits 1 and 2 indicate the flash return status, bits 3 and 4 indicate the flash mode, bit 5 indicates whether the flash function is present, and bit 6 indicates "red eye" mode.

Values for bit 0 indicating whether the flash fired.
0 = Flash did not fire
1 = Flash fired

Values for bits 1 and 2 indicating the status of returned light.
00 = No strobe return detection function
01 = reserved
10 = Strobe return light not detected
11 = Strobe return light detected

Values for bits 3 and 4 indicating the camera's flash mode.
00 = unknown
01 = Compulsory flash firing
10 = Compulsory flash suppression
11 = Auto mode

Values for bit 5 indicating the presence of a flash function.
0 = Flash function present
1 = No flash function

Values for bit 6 indicating the camera's red-eye mode.
0 = No red-eye reduction mode or unknown
1 = Red-eye reduction supported

Not all combinations make sense though. The specification defines these combined values:

hex 0000 = Flash did not fire
hex 0001 = Flash fired
hex 0005 = Strobe return light not detected
hex 0007 = Strobe return light detected
hex 0009 = Flash fired, compulsory flash mode
hex 000D = Flash fired, compulsory flash mode, return light not detected
hex 000F = Flash fired, compulsory flash mode, return light detected
hex 0010 = Flash did not fire, compulsory flash mode
hex 0018 = Flash did not fire, auto mode
hex 0019 = Flash fired, auto mode
hex 001D = Flash fired, auto mode, return light not detected
hex 001F = Flash fired, auto mode, return light detected
hex 0020 = No flash function
hex 0041 = Flash fired, red-eye reduction mode
hex 0045 = Flash fired, red-eye reduction mode, return light not detected
hex 0047 = Flash fired, red-eye reduction mode, return light detected
hex 0049 = Flash fired, compulsory flash mode, red-eye reduction mode
hex 004D = Flash fired, compulsory flash mode, red-eye reduction mode, return light not detected
hex 004F = Flash fired, compulsory flash mode, red-eye reduction mode, return light detected
hex 0059 = Flash fired, auto mode, red-eye reduction mode
hex 005D = Flash fired, auto mode, return light not detected, red-eye reduction mode
hex 005F = Flash fired, auto mode, return light detected, red-eye reduction mode

=========================
 
Last edited:

gadgetmonster

Active Member
Licensed User
Exif data always blank

Hi All

I'm having issues getting to the exif data using this library and could really do with some help please.

I use the contentchooser to allow the user to pic a photo from the camera. Once selected I end up in

B4X:
imageChooser_Result (Success As Boolean, Dir As String, FileName As String)
Which gives me the directory and filename. As a simple test I then do:

B4X:
exif.Initialize(Dir, FileName)
Dim temp As String
temp = exif.getAttribute(exif.TAG_DATETIME)
But temp is always blank. I don't get any exceptions either.

Any ideas?
 

gadgetmonster

Active Member
Licensed User
Just to add, I have copied the images from my device onto my PC to verify that exif data is present and it is. My camera images b y default are stored on my SD card so I have also copied them onto the device itself and still no joy.

When returning from the content chooser, Dir = ContentDir and the Filename = content://media/external/images/media/3425 which is odd as this is not the actual name of the jpg when viewing in windows. Could this be the problem and if so how to get the correct filename.

Thanks in advance :)
 
Last edited:

agraham

Expert
Licensed User
Run the JpegUtils demo and check that the date is shown in the message box that shows when you tap the picture. A blank date may be a sign that the filename or directory is not valid. For some reason the Android ExifInterface object, which this library wraps, does not throw an Exception when initialised with an non-existent file. The initialiser for ExifInterface takes a full path (Android is not very consistent with filenames and paths) which is done like this.
B4X:
exif = new ExifInterface(dir + "/" + filename);
Log your directory and filename and see what they look like.
 

agraham

Expert
Licensed User
From the help for ContentChooser
Note that these values may point to resources other than regular files. Still you can pass them to methods that expect Dir and FileName.
Looks like you need to do some string manipulation.
 

swissmade

Active Member
Licensed User
Copy Image to new resized Image with EXIF data

Hi all,

I wondering, if it is possible, to copy the old EXIF data to the new resized Image.
I have try this but then you must copy Tag for Tag.

Is there an other way to do this.

To explain this better
I take a Picture with my Camera save as "1.jpg"
Then I resize the Image to about 800x600
Save this Image as "2.jpg"
In "1.jpg" I still have the EXIF data and "2.jpg" has no EXIF data.

Many thanks for any help.:sign0163:
 

corvo

Member
Licensed User
Help whit lat and lon

Hi, i have some problem to extract gps coordinates from a jpeg, whit the command

dim test as string

test=exif.getAttribute(exif.TAG_GPS_LATITUDE_REF)
my string contain on a letter: "N", and if i use

dim test as string

test=exif.getAttribute(exif.TAG_GPS_LATITUDE)
my string is made by strange value, like 150/569.456/1452N

how i can take the coords whit your library?

:sign0104::sign0104:
 

corvo

Member
Licensed User
Thank you erel, this is the string
56/1,16973828/65539,393216/1795N

and i got also problem if i try to save the exif data in a string, i need a example :(:sign0104:
 

agraham

Expert
Licensed User
Here is the format of the GPS Exif tags.

TIFF Tag Reference, GPS Tags

By following the links you will see Latitude and Longitude are expressed as three rational numbers.

three RATIONAL values giving the degrees, minutes, and seconds, respectively. If latitude is expressed as degrees, minutes and seconds, a typical format would be dd/1,mm/1,ss/1. When degrees and minutes are used and, for example, fractions of minutes are given up to two decimal places, the format would be dd/1,mmmm/100,0/1.
 
Top