0

I need to take a picture with Android app (either from Camera or from Gallery) and check its EXIF date-time (and a couple other properties). I have successfully implemented recieving of the JPG image and loading it into TStream and GUI Image components. But I'm having trouble extracting the EXIF data.

I've tried the following code (and it's variants available on the internet):

procedure ReadEXIF(aPath: string);
var
  LEXIF: JExifInterface;
  LDateTaken: string;
begin
  // Path looks like:
  // /data/data/com.embarcadero.SimpleLogin/cache/IMG_20190305_085250104151537.jpg
  LEXIF := TJExifInterface.JavaClass.init(StringToJString(aPath));
  LDateTaken := JStringToString(LEXIF.getAttribute(TJExifInterface.JavaClass.TAG_DATETIME));
  Log.d(LDateTaken);
end;

but it returns "Raw image not detected" error.

How do I read the EXIF data?

P.S. Tried the CCR-EXIF lib, but it won't compile for FMX (too many Ansi references throughout its code).
P.P.S. I've verified that received image has EXIF data (saved it from stream to other location and checked)

Kromster
  • 7,181
  • 7
  • 63
  • 111

1 Answers1

0

I was able to read the EXIF by using the following low-level code (changing few stray Chars to Bytes to make it compile and work for Android/FMX): http://www.bvbcode.com/code/37ghxe42-1643402

ex := TExif.Create;
ex.ReadFromFile(aPath);
Log.d('DateTime: %s', [ex.DateTime]);
ex.Free;

Another working method is available here: https://github.com/DelphiWorlds/KastriFree/tree/master/Demos/ObtainPhotoInfoDemo The demo basically tells the OS to take a photo and save it under specified filename. Later that filename can be used to extract EXIF info.

Kromster
  • 7,181
  • 7
  • 63
  • 111