Android Question SimpleMediaManager metadata or EXIF

koffie

Member
Licensed User
Longtime User
Hello,

Using SMM with setmediafromfile to load jpegs. Working perfectly.

I would like to know some parts of the meta / exif data, but especially the present orientation (Human readable, width/height, or orientation numbers)

The only thing I see is preprocessexif (which syntax i do not understand at all) to SET the orientation.

Is there a way in which I can see the present orientation of the JPEG?

Regards,
 

Mark Read

Well-Known Member
Licensed User
Longtime User
Its a long time since I worked with EXIF data but I was using metadata-extractor, which is a java file (you will need to search and download the jar). The information for the orientation you can find here. I was using the following code in a B4J app:

Code from B4J:
#Region  Project Attributes
  #MainFormWidth: 600
  #MainFormHeight: 400
  #AdditionalJar: metadata-extractor-2.11.0        'Change the name accordingly!'
#End Region

Sub Process_Globals
  Private fx As JFX
  Private MainForm As Form
  Private NativeMe As JavaObject
End Sub

Sub AppStart (Form1 As Form, Args() As String)
  MainForm = Form1
  MainForm.Show
    
  NativeMe = Me
 
  Dim fn As String = "test.jpg"

Dim imgmeta As List = NativeMe.RunMethod("GetImgMeta", Array(fn))
      
    For Each s1 As String In imgmeta
        Log(s1)
    Next
End Sub

#If JAVA
import com.drew.imaging.*;
import com.drew.metadata.*;
import com.drew.lang.*;

import java.io.*;
import java.util.*;

public static List GetImgMeta(String filename)
{
  File file = new File(filename);
  List lstMeta = new ArrayList<Object>();
 
  try {
    Metadata metadata = ImageMetadataReader.readMetadata(file);

    for (Directory directory : metadata.getDirectories()) {
      for (Tag tag : directory.getTags()) {
        lstMeta.add(tag.toString());
      }

      if (directory.hasErrors()) {
        for (String error : directory.getErrors()) {
          System.err.println("ERROR: " + error);
        }
      }
    }
  }
  catch (ImageProcessingException e) {
    // handle exception
    lstMeta.add("ImageProcessingException");
  }
  catch (IOException e) {
    // handle exception
    lstMeta.add("IOException");
  }
 
  return(lstMeta);
}
#End If

Maybe this helps you a little.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is the relevant code in SMM that reads the orientation:
B4X:
Dim MetadataReader As JavaObject
    Dim ExifReader As JavaObject
    ExifReader.InitializeNewInstance("com.drew.metadata.exif.ExifReader", Null)
    Dim readers As List = Array(ExifReader)
    Try
        Dim Metadata As JavaObject = MetadataReader.InitializeStatic("com.drew.imaging.jpeg.JpegMetadataReader").RunMethod("readMetadata", Array(In, readers))
        For Each dic As JavaObject In Metadata.RunMethod("getDirectories", Null).As(List)
            Dim orientation As Object = dic.RunMethod("getInteger", Array(274)) 'orientation
            If orientation <> Null Then
                Media.Media = RotateBitmapBasedOnOrientation(Media.Media, orientation)
                Exit
            End If
        Next
    Catch
        Log(LastException)
    End Try
274 is the "tag" value of orientation.

You can see other values here: https://developer.android.com/reference/androidx/exifinterface/media/ExifInterface
 
Upvote 0
Top