use of com.drew.metadata.Directory in project react-native-camera by lwansbrough.
the class MutableImage method writeDataToFile.
public void writeDataToFile(File file, ReadableMap options, int jpegQualityPercent) throws IOException {
FileOutputStream fos = new FileOutputStream(file);
fos.write(toJpeg(currentRepresentation, jpegQualityPercent));
fos.close();
try {
ExifInterface exif = new ExifInterface(file.getAbsolutePath());
// copy original exif data to the output exif...
for (Directory directory : originalImageMetaData().getDirectories()) {
for (Tag tag : directory.getTags()) {
int tagType = tag.getTagType();
Object object = directory.getObject(tagType);
exif.setAttribute(tag.getTagName(), object.toString());
}
}
// Add missing exif data from a sub directory
ExifSubIFDDirectory directory = originalImageMetaData().getFirstDirectoryOfType(ExifSubIFDDirectory.class);
for (Tag tag : directory.getTags()) {
int tagType = tag.getTagType();
// As some of exif data does not follow naming of the ExifInterface the names need
// to be transformed into Upper camel case format.
String tagName = tag.getTagName().replaceAll(" ", "");
Object object = directory.getObject(tagType);
if (tagName.equals(ExifInterface.TAG_EXPOSURE_TIME)) {
exif.setAttribute(tagName, convertExposureTimeToDoubleFormat(object.toString()));
} else {
exif.setAttribute(tagName, object.toString());
}
}
writeLocationExifData(options, exif);
if (hasBeenReoriented)
rewriteOrientation(exif);
exif.saveAttributes();
} catch (ImageProcessingException | IOException e) {
Log.e(TAG, "failed to save exif data", e);
}
}
use of com.drew.metadata.Directory in project react-native-camera by react-native-community.
the class MutableImage method writeDataToFile.
public void writeDataToFile(File file, ReadableMap options, int jpegQualityPercent) throws IOException {
FileOutputStream fos = new FileOutputStream(file);
fos.write(toJpeg(currentRepresentation, jpegQualityPercent));
fos.close();
try {
ExifInterface exif = new ExifInterface(file.getAbsolutePath());
// copy original exif data to the output exif...
for (Directory directory : originalImageMetaData().getDirectories()) {
for (Tag tag : directory.getTags()) {
int tagType = tag.getTagType();
Object object = directory.getObject(tagType);
exif.setAttribute(tag.getTagName(), object.toString());
}
}
// Add missing exif data from a sub directory
ExifSubIFDDirectory directory = originalImageMetaData().getFirstDirectoryOfType(ExifSubIFDDirectory.class);
for (Tag tag : directory.getTags()) {
int tagType = tag.getTagType();
// As some of exif data does not follow naming of the ExifInterface the names need
// to be transformed into Upper camel case format.
String tagName = tag.getTagName().replaceAll(" ", "");
Object object = directory.getObject(tagType);
if (tagName.equals(ExifInterface.TAG_EXPOSURE_TIME)) {
exif.setAttribute(tagName, convertExposureTimeToDoubleFormat(object.toString()));
} else {
exif.setAttribute(tagName, object.toString());
}
}
writeLocationExifData(options, exif);
if (hasBeenReoriented)
rewriteOrientation(exif);
exif.saveAttributes();
} catch (ImageProcessingException | IOException e) {
Log.e(TAG, "failed to save exif data", e);
}
}
Aggregations