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