Class ExifTag
-
- All Implemented Interfaces:
public class ExifTag
This class stores information of an EXIF tag. For more information about defined EXIF tags, please read the Jeita EXIF 2.2 standard. Tags should be instantiated using buildTag.
-
-
Field Summary
Fields Modifier and Type Field Description public final static short
TYPE_UNSIGNED_BYTE
public final static short
TYPE_ASCII
public final static short
TYPE_UNSIGNED_SHORT
public final static short
TYPE_UNSIGNED_LONG
public final static short
TYPE_UNSIGNED_RATIONAL
public final static short
TYPE_UNDEFINED
public final static short
TYPE_LONG
public final static short
TYPE_RATIONAL
-
Method Summary
Modifier and Type Method Description static boolean
isValidIfd(int ifdId)
Returns true if the given IFD is a valid IFD. static boolean
isValidType(short type)
Returns true if a given type is a valid tag type. static int
getElementSize(short type)
Gets the element size of the given data type in bytes. int
getIfd()
Returns the ID of the IFD this tag belongs to. short
getTagId()
Gets the TID of this tag. short
getDataType()
Gets the data type of this tag int
getDataSize()
Gets the total data size in bytes of the value of this tag. int
getComponentCount()
Gets the component count of this tag. boolean
hasValue()
Returns true if this ExifTag contains value; otherwise, this tag will contain an offset value that is determined when the tag is written. boolean
setValue(Array<int> value)
Sets integer values into this tag. boolean
setValue(int value)
Sets integer value into this tag. boolean
setValue(Array<long> value)
Sets long values into this tag. boolean
setValue(long value)
Sets long values into this tag. boolean
setValue(String value)
Sets a string value into this tag. boolean
setValue(Array<Rational> value)
Sets Rational values into this tag. boolean
setValue(Rational value)
Sets a Rational value into this tag. boolean
setValue(Array<byte> value, int offset, int length)
Sets byte values into this tag. boolean
setValue(Array<byte> value)
Equivalent to setValue(value, 0, value.length). boolean
setValue(byte value)
Sets byte value into this tag. boolean
setValue(Object obj)
Sets the value for this tag using an appropriate setValue method for the given object. boolean
setTimeValue(long time)
Sets a timestamp to this tag. String
getValueAsString()
Gets the value as a String. String
getValueAsString(String defaultValue)
Gets the value as a String. Array<byte>
getValueAsBytes()
Gets the value as a byte array. byte
getValueAsByte(byte defaultValue)
Gets the value as a byte. Array<Rational>
getValueAsRationals()
Gets the value as an array of Rationals. Rational
getValueAsRational(Rational defaultValue)
Gets the value as a Rational. Rational
getValueAsRational(long defaultValue)
Gets the value as a Rational. Array<int>
getValueAsInts()
Gets the value as an array of ints. int
getValueAsInt(int defaultValue)
Gets the value as an int. Array<long>
getValueAsLongs()
Gets the value as an array of longs. long
getValueAsLong(long defaultValue)
Gets the value or null if none exists. Object
getValue()
Gets the tag's value or null if none exists. long
forceGetValueAsLong(long defaultValue)
Gets a long representation of the value. String
forceGetValueAsString()
Gets a string representation of the value. boolean
equals(Object obj)
String
toString()
-
-
Method Detail
-
isValidIfd
static boolean isValidIfd(int ifdId)
Returns true if the given IFD is a valid IFD.
-
isValidType
static boolean isValidType(short type)
Returns true if a given type is a valid tag type.
-
getElementSize
static int getElementSize(short type)
Gets the element size of the given data type in bytes.
-
getIfd
int getIfd()
Returns the ID of the IFD this tag belongs to.
-
getTagId
short getTagId()
Gets the TID of this tag.
-
getDataType
short getDataType()
Gets the data type of this tag
-
getDataSize
int getDataSize()
Gets the total data size in bytes of the value of this tag.
-
getComponentCount
int getComponentCount()
Gets the component count of this tag.
-
hasValue
boolean hasValue()
Returns true if this ExifTag contains value; otherwise, this tag will contain an offset value that is determined when the tag is written.
-
setValue
boolean setValue(Array<int> value)
Sets integer values into this tag. This method should be used for tags of type TYPE_UNSIGNED_SHORT. This method will fail if:
- The component type of this tag is not TYPE_UNSIGNED_SHORT, TYPE_UNSIGNED_LONG, or TYPE_LONG.
- The value overflows.
- The value.length does NOT match the component count in the definition for this tag.
-
setValue
boolean setValue(int value)
Sets integer value into this tag. This method should be used for tags of type TYPE_UNSIGNED_SHORT, or TYPE_LONG. This method will fail if:
- The component type of this tag is not TYPE_UNSIGNED_SHORT, TYPE_UNSIGNED_LONG, or TYPE_LONG.
- The value overflows.
- The component count in the definition of this tag is not 1.
-
setValue
boolean setValue(Array<long> value)
Sets long values into this tag. This method should be used for tags of type TYPE_UNSIGNED_LONG. This method will fail if:
- The component type of this tag is not TYPE_UNSIGNED_LONG.
- The value overflows.
- The value.length does NOT match the component count in the definition for this tag.
-
setValue
boolean setValue(long value)
Sets long values into this tag. This method should be used for tags of type TYPE_UNSIGNED_LONG. This method will fail if:
- The component type of this tag is not TYPE_UNSIGNED_LONG.
- The value overflows.
- The component count in the definition for this tag is not 1.
-
setValue
boolean setValue(String value)
Sets a string value into this tag. This method should be used for tags of type TYPE_ASCII. The string is converted to an ASCII string. Characters that cannot be converted are replaced with '?'. The length of the string must be equal to either (component count -1) or (component count). The final byte will be set to the string null terminator '\0', overwriting the last character in the string if the value.length is equal to the component count. This method will fail if:
- The data type is not TYPE_ASCII or TYPE_UNDEFINED.
- The length of the string is not equal to (component count -1) or (component count) in the definition for this tag.
-
setValue
boolean setValue(Array<Rational> value)
Sets Rational values into this tag. This method should be used for tags of type TYPE_UNSIGNED_RATIONAL, or TYPE_RATIONAL. This method will fail if:
- The component type of this tag is not TYPE_UNSIGNED_RATIONAL or TYPE_RATIONAL.
- The value overflows.
- The value.length does NOT match the component count in the definition for this tag.
-
setValue
boolean setValue(Rational value)
Sets a Rational value into this tag. This method should be used for tags of type TYPE_UNSIGNED_RATIONAL, or TYPE_RATIONAL. This method will fail if:
- The component type of this tag is not TYPE_UNSIGNED_RATIONAL or TYPE_RATIONAL.
- The value overflows.
- The component count in the definition for this tag is not 1.
-
setValue
boolean setValue(Array<byte> value, int offset, int length)
Sets byte values into this tag. This method should be used for tags of type TYPE_UNSIGNED_BYTE or TYPE_UNDEFINED. This method will fail if:
- The component type of this tag is not TYPE_UNSIGNED_BYTE or TYPE_UNDEFINED .
- The length does NOT match the component count in the definition for this tag.
-
setValue
boolean setValue(byte value)
Sets byte value into this tag. This method should be used for tags of type TYPE_UNSIGNED_BYTE or TYPE_UNDEFINED. This method will fail if:
- The component type of this tag is not TYPE_UNSIGNED_BYTE or TYPE_UNDEFINED .
- The component count in the definition for this tag is not 1.
-
setValue
boolean setValue(Object obj)
Sets the value for this tag using an appropriate setValue method for the given object. This method will fail if:
- The corresponding setValue method for the class of the object passed in would fail.
- There is no obvious way to cast the object passed in into an EXIF tag type.
-
setTimeValue
boolean setTimeValue(long time)
Sets a timestamp to this tag. The method converts the timestamp with the format of "yyyy:MM:dd kk:mm:ss" and calls setValue. This method will fail if the data type is not TYPE_ASCII or the component count of this tag is not 20 or undefined.
- Parameters:
time
- the number of milliseconds since Jan.
-
getValueAsString
String getValueAsString()
Gets the value as a String. This method should be used for tags of type TYPE_ASCII.
-
getValueAsString
String getValueAsString(String defaultValue)
Gets the value as a String. This method should be used for tags of type TYPE_ASCII.
- Parameters:
defaultValue
- the String to return if the tag's value does not exist or cannot be converted to a String.
-
getValueAsBytes
Array<byte> getValueAsBytes()
Gets the value as a byte array. This method should be used for tags of type TYPE_UNDEFINED or TYPE_UNSIGNED_BYTE.
-
getValueAsByte
byte getValueAsByte(byte defaultValue)
Gets the value as a byte. If there are more than 1 bytes in this value, gets the first byte. This method should be used for tags of type TYPE_UNDEFINED or TYPE_UNSIGNED_BYTE.
- Parameters:
defaultValue
- the byte to return if tag's value does not exist or cannot be converted to a byte.
-
getValueAsRationals
Array<Rational> getValueAsRationals()
Gets the value as an array of Rationals. This method should be used for tags of type TYPE_RATIONAL or TYPE_UNSIGNED_RATIONAL.
-
getValueAsRational
Rational getValueAsRational(Rational defaultValue)
Gets the value as a Rational. If there are more than 1 Rationals in this value, gets the first one. This method should be used for tags of type TYPE_RATIONAL or TYPE_UNSIGNED_RATIONAL.
- Parameters:
defaultValue
- the Rational to return if tag's value does not exist or cannot be converted to a Rational.
-
getValueAsRational
Rational getValueAsRational(long defaultValue)
Gets the value as a Rational. If there are more than 1 Rationals in this value, gets the first one. This method should be used for tags of type TYPE_RATIONAL or TYPE_UNSIGNED_RATIONAL.
- Parameters:
defaultValue
- the numerator of the Rational to return if tag's value does not exist or cannot be converted to a Rational (the denominator will be 1).
-
getValueAsInts
Array<int> getValueAsInts()
Gets the value as an array of ints. This method should be used for tags of type TYPE_UNSIGNED_SHORT, TYPE_UNSIGNED_LONG.
-
getValueAsInt
int getValueAsInt(int defaultValue)
Gets the value as an int. If there are more than 1 ints in this value, gets the first one. This method should be used for tags of type TYPE_UNSIGNED_SHORT, TYPE_UNSIGNED_LONG.
- Parameters:
defaultValue
- the int to return if tag's value does not exist or cannot be converted to an int.
-
getValueAsLongs
Array<long> getValueAsLongs()
Gets the value as an array of longs. This method should be used for tags of type TYPE_UNSIGNED_LONG.
-
getValueAsLong
long getValueAsLong(long defaultValue)
Gets the value or null if none exists. If there are more than 1 longs in this value, gets the first one. This method should be used for tags of type TYPE_UNSIGNED_LONG.
- Parameters:
defaultValue
- the long to return if tag's value does not exist or cannot be converted to a long.
-
forceGetValueAsLong
long forceGetValueAsLong(long defaultValue)
Gets a long representation of the value.
- Parameters:
defaultValue
- value to return if there is no value or value is a rational with a denominator of 0.
-
forceGetValueAsString
String forceGetValueAsString()
Gets a string representation of the value.
-
-
-
-