如何通过rational从android中的照片属性获取曝光时间?

如何通过rational从android中的照片属性获取曝光时间?,android,gallery,rational-number,Android,Gallery,Rational Number,我正在写图库。但是当我使用exifInterface.getAttribute(exifInterface.TAG\u EXPOSURE\u TIME)时,我得到了double,它应该是有理数(分数)。如果我打开系统库,它是合理的。请帮助我。谢谢。要获得精确/正确的值,请使用新的而不是旧的ExiFinInterface 您必须将以下内容添加到渐变中: compile "com.android.support:exifinterface:25.1.0" 然后确保使用新的android.suppo

我正在写图库。但是当我使用
exifInterface.getAttribute(exifInterface.TAG\u EXPOSURE\u TIME)
时,我得到了
double
,它应该是有理数(分数)。如果我打开系统库,它是合理的。请帮助我。谢谢。

要获得精确/正确的值,请使用新的而不是旧的ExiFinInterface

您必须将以下内容添加到渐变中:

compile "com.android.support:exifinterface:25.1.0"
然后确保使用新的android.support.media.ExifInterface库,而不是旧的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;
}
导入android.support.media.ExifInterface;
字符串getExposureTime(最终ExiFinInterface exif)
{
String exposureTime=exif.getAttribute(ExifInterface.TAG\u EXPOSURE\u TIME);
if(exposureTime!=null)
{
exposureTime=formatExposureTime(Double.valueof(exposureTime));
}
返回曝光时间;
}
公共静态字符串formatExposureTime(最终双精度值)
{
字符串输出;
如果(值<1.0f)
{
output=String.format(Locale.getDefault(),%d/%d',1,(int)(0.5f+1/值));
}
其他的
{
最终整数=(int)值;
最终双精度时间=值-整数;
输出=String.format(Locale.getDefault(),%d'',整数);
如果(时间>0.0001f)
{
output+=String.format(Locale.getDefault(),%d/%d',1,(int)(0.5f+1/次));
}
}
返回输出;
}

要获得精确/正确的值,请使用新的而不是旧的ExiFinInterface

您必须将以下内容添加到渐变中:

compile "com.android.support:exifinterface:25.1.0"
然后确保使用新的android.support.media.ExifInterface库,而不是旧的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;
}
导入android.support.media.ExifInterface;
字符串getExposureTime(最终ExiFinInterface exif)
{
String exposureTime=exif.getAttribute(ExifInterface.TAG\u EXPOSURE\u TIME);
if(exposureTime!=null)
{
exposureTime=formatExposureTime(Double.valueof(exposureTime));
}
返回曝光时间;
}
公共静态字符串formatExposureTime(最终双精度值)
{
字符串输出;
如果(值<1.0f)
{
output=String.format(Locale.getDefault(),%d/%d',1,(int)(0.5f+1/值));
}
其他的
{
最终整数=(int)值;
最终双精度时间=值-整数;
输出=String.format(Locale.getDefault(),%d'',整数);
如果(时间>0.0001f)
{
output+=String.format(Locale.getDefault(),%d/%d',1,(int)(0.5f+1/次));
}
}
返回输出;
}

谢谢你的回答。你的代码让我更接近事实,它是合理的,但并不准确。有一张图片,我得到1/323使用你的代码,但在windows中是1/328。问题是你仍然使用旧的android.media.ExifInterface,这将使你的测试照片的曝光时间不太准确,为0.0031。相反,您必须向项目中添加来自Google的新android.support.media.ExifInterface库,并改用此库。这将为您提供正确的精度0.003053,因此值为1/328。请看上面的算法解释。谢谢你给出答案。你的代码让我接近事实,它是合理的,但不准确。有一张图片,我得到1/323使用你的代码,但在windows中是1/328。问题是你仍然在使用旧的android.media.ExifInterface,这将使您的测试照片的曝光时间不太精确,为0.0031。相反,您必须向项目中添加来自Google的新android.support.media.ExifInterface库,并改用此库。这将为您提供正确的精度0.003053,因此值为1/328。请参见上述算法的说明。