File jpegFile = new File(filename);
try {
Metadata metadata = JpegMetadataReader.readMetadata(jpegFile);
if (metadata.containsDirectory(ExifDirectory.class)) {
Directory exifDirectory = metadata.getDirectory(ExifDirectory.class);
try {
String camera = exifDirectory.getString(ExifDirectory.TAG_MODEL);
image.setValue(Image._Q_CAMERA, camera);
} catch (Exception me) {}
try {
int compression = exifDirectory.getInt(ExifDirectory.TAG_COMPRESSION);
image.setValue(Image._O_COMPRESSION, Long.valueOf(compression));
} catch (Exception me) {}
try {
String description = exifDirectory.getString(ExifDirectory.TAG_IMAGE_DESCRIPTION);
image.setValue(Image._B_DESCRIPTION, description);
} catch (Exception me) {}
try {
Date date = exifDirectory.getDate(ExifDirectory.TAG_DATETIME);
if (date != null) {
cal.setTime(date);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
image.setValue(Image._N_DATE, cal.getTime());
}
} catch (Exception me) {}
}
if (metadata.containsDirectory(IptcDirectory.class)) {
try {
Directory iptcDirectory = metadata.getDirectory(IptcDirectory.class);
String city = iptcDirectory.getString(IptcDirectory.TAG_CITY);
String country = iptcDirectory.getString(IptcDirectory.TAG_COUNTRY_OR_PRIMARY_LOCATION);
String state = iptcDirectory.getString(IptcDirectory.TAG_PROVINCE_OR_STATE);
String location = "";
location += country != null ? country + ", " : "";
location += state != null ? state + ", " : "";
location += city != null ? city : "";