0

I'm writing gallery.But I got double when i use exifInterface.getAttribute(ExifInterface.TAG_EXPOSURE_TIME), it should be rational(fraction). If I open system gallery, it is rational.Please help me.Thanks.

arjun
  • 3,514
  • 4
  • 27
  • 48
jianhua
  • 3
  • 3

1 Answers1

2

To get precise/correct values use the new ExifInterface support library instead of the old ExifInterface.

You must add to your gradle:

compile "com.android.support:exifinterface:25.1.0"

And then ensure you use the new android.support.media.ExifInterface library instead of the old android.media.ExifInterface.

import android.support.media.ExifInterface;

String getExposureTime(final ExifInterface exif)
{
    String exposureTime = exif.getAttribute(ExifInterface.TAG_EXPOSURE_TIME);

    if (exposureTime != null)
    {
        exposureTime = formatExposureTime(Double.valudeOf(exposureTime));
    }

    return exposureTime;
}

public static String formatExposureTime(final double value)
{
    String output;

    if (value < 1.0f)
    {
        output = String.format(Locale.getDefault(), "%d/%d", 1, (int)(0.5f + 1 / value));
    }
    else
    {
        final int    integer = (int)value;
        final double time    = value - integer;
        output = String.format(Locale.getDefault(), "%d''", integer);

        if (time > 0.0001f)
        {
            output += String.format(Locale.getDefault(), " %d/%d", 1, (int)(0.5f + 1 / time));
        }
    }

    return output;
}
PerracoLabs
  • 16,449
  • 15
  • 74
  • 127
  • Thank you give the answer.Your code make me close to the truth, it is rational but not accurate.There is a picture[link](https://pan.baidu.com/s/1dEBcSAd),i get 1/323 use your code,but it is 1/328 in windows . – jianhua Apr 12 '17 at 06:16
  • The problem is that you are still using the old android.media.ExifInterface, which will give you a less precise Exposure-Time of 0.0031 from your test photo. Instead you must add to your project the new android.support.media.ExifInterface library from Google and use this one instead. which will give you the correct precision of 0.003053, and therefore the value 1/328. Please see the explanation above the algorithm. – PerracoLabs Apr 12 '17 at 12:18