0
我正在写gallery.But我double
当我使用exifInterface.getAttribute(ExifInterface.TAG_EXPOSURE_TIME)
,它应该是理性的(分数)。如果我打开系统库,它是合理的。请帮助我。谢谢。如何从android的照片属性理性曝光时间?
我正在写gallery.But我double
当我使用exifInterface.getAttribute(ExifInterface.TAG_EXPOSURE_TIME)
,它应该是理性的(分数)。如果我打开系统库,它是合理的。请帮助我。谢谢。如何从android的照片属性理性曝光时间?
要获得精确/正确的值,请使用新的ExifInterface support library而不是旧的ExifInterface。
您必须添加到您的gradle产出:
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;
}
谢谢你给出的答案。你的代码使我接近真相,它是合理的,但不准确。有一张图片[链接](https://pan.baidu.com/s/1dEBcSAd) ,我得到1/323使用你的代码,但它在Windows中是1/328。 – jianhua
问题是,你仍然在使用旧的android.media.ExifInterface,它会给你从测试照片中获得0.0031的不准确曝光时间。相反,您必须向您的项目添加新的来自Google的android.support.media.ExifInterface库,然后使用此库。这会给你0.003053的正确精度,因此它的值为1/328。请参阅上述算法的解释。 – PerracoLabs