本文整理汇总了Java中com.drew.lang.Rational类的典型用法代码示例。如果您正苦于以下问题:Java Rational类的具体用法?Java Rational怎么用?Java Rational使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Rational类属于com.drew.lang包,在下文中一共展示了Rational类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDecimalCoordinatesAsFloat
import com.drew.lang.Rational; //导入依赖的package包/类
private static Float getDecimalCoordinatesAsFloat(String orientation, Rational[] coordinates) {
if (orientation == null) {
log.debug("GPS orientation is null, should be N, S, E, or W.");
return null;
}
if (coordinates == null) {
log.debug("GPS coordinates are null.");
return null;
}
if (coordinates[0].getDenominator() == 0 || coordinates[1].getDenominator() == 0
|| coordinates[2].getDenominator() == 0) {
log.debug("Invalid GPS coordinates (denominator should not be 0).");
return null;
}
float m = 1;
if (orientation.toUpperCase().charAt(0) == 'S' || orientation.toUpperCase().charAt(0) == 'W') {
m = -1;
}
float deg = coordinates[0].getNumerator() / coordinates[0].getDenominator();
float min = coordinates[1].getNumerator() * 60 * coordinates[2].getDenominator();
float sec = coordinates[2].getNumerator();
float den = 3600 * coordinates[1].getDenominator() * coordinates[2].getDenominator();
return m * (deg + (min + sec) / den);
}
示例2: getGeoLocation
import com.drew.lang.Rational; //导入依赖的package包/类
/**
* Parses various tags in an attempt to obtain a single object representing the latitude and longitude
* at which this image was captured.
*
* @return The geographical location of this image, if possible, otherwise null
*/
@Nullable
public GeoLocation getGeoLocation()
{
Rational[] latitudes = getRationalArray(TAG_LATITUDE);
Rational[] longitudes = getRationalArray(TAG_LONGITUDE);
String latitudeRef = getString(TAG_LATITUDE_REF);
String longitudeRef = getString(TAG_LONGITUDE_REF);
// Make sure we have the required values
if (latitudes == null || latitudes.length != 3)
return null;
if (longitudes == null || longitudes.length != 3)
return null;
if (latitudeRef == null || longitudeRef == null)
return null;
Double lat = GeoLocation.degreesMinutesSecondsToDecimal(latitudes[0], latitudes[1], latitudes[2], latitudeRef.equalsIgnoreCase("S"));
Double lon = GeoLocation.degreesMinutesSecondsToDecimal(longitudes[0], longitudes[1], longitudes[2], longitudeRef.equalsIgnoreCase("W"));
// This can return null, in cases where the conversion was not possible
if (lat == null || lon == null)
return null;
return new GeoLocation(lat, lon);
}
示例3: getFocusDistanceDescription
import com.drew.lang.Rational; //导入依赖的package包/类
@Nullable
public String getFocusDistanceDescription()
{
Rational value = _directory.getRational(TagFocusDistance);
if (value == null)
return "inf";
if (value.getNumerator() == 0xFFFFFFFFL || value.getNumerator() == 0x00000000L)
return "inf";
return value.getNumerator() / 1000.0 + " m";
}
示例4: getAfPointSelectedDescription
import com.drew.lang.Rational; //导入依赖的package包/类
@Nullable
public String getAfPointSelectedDescription()
{
Rational[] values = _directory.getRationalArray(TagAfPointSelected);
if (values == null)
return "n/a";
if (values.length < 4)
return null;
int index = 0;
if (values.length == 5 && values[0].longValue() == 0)
index = 1;
int p1 = (int)(values[index].doubleValue() * 100);
int p2 = (int)(values[index + 1].doubleValue() * 100);
int p3 = (int)(values[index + 2].doubleValue() * 100);
int p4 = (int)(values[index + 3].doubleValue() * 100);
if(p1 + p2 + p3 + p4 == 0)
return "n/a";
return String.format("(%d%%,%d%%) (%d%%,%d%%)", p1, p2, p3, p4);
}
示例5: getManualFlashStrengthDescription
import com.drew.lang.Rational; //导入依赖的package包/类
@Nullable
public String getManualFlashStrengthDescription()
{
Rational[] values = _directory.getRationalArray(TagManualFlashStrength);
if (values == null || values.length == 0)
return "n/a";
if (values.length == 3) {
if (values[0].getDenominator() == 0 && values[1].getDenominator() == 0 && values[2].getDenominator() == 0)
return "n/a";
} else if (values.length == 4) {
if (values[0].getDenominator() == 0 && values[1].getDenominator() == 0 && values[2].getDenominator() == 0 && values[3].getDenominator() == 0)
return "n/a (x4)";
}
StringBuilder sb = new StringBuilder();
for (Rational t : values)
sb.append(t).append(", ");
return sb.substring(0, sb.length() - 2);
}
示例6: getYCbCrCoefficientsDescription
import com.drew.lang.Rational; //导入依赖的package包/类
@Nullable
public String getYCbCrCoefficientsDescription()
{
int[] values = _directory.getIntArray(TagYCbCrCoefficients);
if (values == null)
return null;
Rational[] ret = new Rational[values.length / 2];
for(int i = 0; i < values.length / 2; i++)
{
ret[i] = new Rational((short)values[2*i], (short)values[2*i + 1]);
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < ret.length; i++) {
sb.append(ret[i].doubleValue());
if (i < ret.length - 1)
sb.append(" ");
}
return sb.length() == 0 ? null : sb.toString();
}
示例7: getRational
import com.drew.lang.Rational; //导入依赖的package包/类
/** Returns the specified tag's value as a Rational. If the value is unset or cannot be converted, <code>null</code> is returned. */
@Nullable
public Rational getRational(int tagType)
{
Object o = getObject(tagType);
if (o == null)
return null;
if (o instanceof Rational)
return (Rational)o;
if (o instanceof Integer)
return new Rational((Integer)o, 1);
if (o instanceof Long)
return new Rational((Long)o, 1);
// NOTE not doing conversions for real number types
return null;
}
示例8: testUnderlyingInt
import com.drew.lang.Rational; //导入依赖的package包/类
@Test
public void testUnderlyingInt() throws Exception
{
int value = 123;
int tagType = 321;
_directory.setInt(tagType, value);
assertEquals(value, _directory.getInt(tagType));
assertEquals(Integer.valueOf(value), _directory.getInteger(tagType));
assertEquals((float)value, _directory.getFloat(tagType), 0.00001);
assertEquals((double)value, _directory.getDouble(tagType), 0.00001);
assertEquals((long)value, _directory.getLong(tagType));
assertEquals(Integer.toString(value), _directory.getString(tagType));
assertEquals(new Rational(value, 1), _directory.getRational(tagType));
assertArrayEquals(new int[]{value}, _directory.getIntArray(tagType));
assertArrayEquals(new byte[]{(byte)value}, _directory.getByteArray(tagType));
}
示例9: getFocalPlaneYResolutionDescription
import com.drew.lang.Rational; //导入依赖的package包/类
@Nullable
public String getFocalPlaneYResolutionDescription()
{
Rational rational = _directory.getRational(TAG_FOCAL_PLANE_Y_RESOLUTION);
if (rational == null)
return null;
final String unit = getFocalPlaneResolutionUnitDescription();
return rational.getReciprocal().toSimpleString(_allowDecimalRepresentationOfRationals)
+ (unit == null ? "" : " " + unit.toLowerCase());
}
示例10: addMetadata
import com.drew.lang.Rational; //导入依赖的package包/类
public void addMetadata(QuickTimeDirectory directory)
{
// Get creation/modification times
Calendar calendar = Calendar.getInstance();
calendar.set(1904, 0, 1, 0, 0, 0); // January 1, 1904 - Macintosh Time Epoch
Date date = calendar.getTime();
long macToUnixEpochOffset = date.getTime();
directory.setDate(TAG_CREATION_TIME, new Date((creationTime * 1000) + macToUnixEpochOffset));
directory.setDate(TAG_MODIFICATION_TIME, new Date((modificationTime * 1000) + macToUnixEpochOffset));
// Get duration and time scale
directory.setLong(TAG_DURATION, duration);
directory.setLong(TAG_TIME_SCALE, timescale);
directory.setRational(QuickTimeDirectory.TAG_DURATION_SECONDS, new Rational(duration, timescale));
// Calculate preferred rate fixed point
double preferredRateInteger = (preferredRate & 0xFFFF0000) >> 16;
double preferredRateFraction = (preferredRate & 0x0000FFFF) / Math.pow(2, 4);
directory.setDouble(TAG_PREFERRED_RATE, preferredRateInteger + preferredRateFraction);
// Calculate preferred volume fixed point
double preferredVolumeInteger = (preferredVolume & 0xFF00) >> 8;
double preferredVolumeFraction = (preferredVolume & 0x00FF) / Math.pow(2, 2);
directory.setDouble(TAG_PREFERRED_VOLUME, preferredVolumeInteger + preferredVolumeFraction);
directory.setLong(TAG_PREVIEW_TIME, previewTime);
directory.setLong(TAG_PREVIEW_DURATION, previewDuration);
directory.setLong(TAG_POSTER_TIME, posterTime);
directory.setLong(TAG_SELECTION_TIME, selectionTime);
directory.setLong(TAG_SELECTION_DURATION, selectionDuration);
directory.setLong(TAG_CURRENT_TIME, currentTime);
directory.setLong(TAG_NEXT_TRACK_ID, nextTrackID);
}
示例11: getDistortionParam02Description
import com.drew.lang.Rational; //导入依赖的package包/类
@Nullable
public String getDistortionParam02Description()
{
Integer value = _directory.getInteger(TagDistortionParam02);
if (value == null)
return null;
return new Rational(value, 32678).toString();
}
示例12: getDistortionParam04Description
import com.drew.lang.Rational; //导入依赖的package包/类
@Nullable
public String getDistortionParam04Description()
{
Integer value = _directory.getInteger(TagDistortionParam04);
if (value == null)
return null;
return new Rational(value, 32678).toString();
}
示例13: getDistortionParam08Description
import com.drew.lang.Rational; //导入依赖的package包/类
@Nullable
public String getDistortionParam08Description()
{
Integer value = _directory.getInteger(TagDistortionParam08);
if (value == null)
return null;
return new Rational(value, 32678).toString();
}
示例14: getFNumberDescription
import com.drew.lang.Rational; //导入依赖的package包/类
/** Do a simple formatting like ExifSubIFDDescriptor.java */
@Nullable
public String getFNumberDescription()
{
final Rational value = _directory.getRational(XmpDirectory.TAG_F_NUMBER);
if (value==null)
return null;
return "F" + SimpleDecimalFormatter.format(value.doubleValue());
}
示例15: getDistortionParam11Description
import com.drew.lang.Rational; //导入依赖的package包/类
@Nullable
public String getDistortionParam11Description()
{
Integer value = _directory.getInteger(TagDistortionParam11);
if (value == null)
return null;
return new Rational(value, 32678).toString();
}