use of androidx.exifinterface.media.ExifInterface in project react-native-camera by lwansbrough.
the class FileFaceDetectionAsyncTask method doInBackground.
@Override
protected Void doInBackground(Void... voids) {
if (isCancelled()) {
return null;
}
mRNFaceDetector = detectorForOptions(mOptions, mContext);
try {
ExifInterface exif = new ExifInterface(mPath);
mOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
} catch (IOException e) {
Log.e(ERROR_TAG, "Reading orientation from file `" + mPath + "` failed.", e);
}
try {
InputImage image = InputImage.fromFilePath(mContext, Uri.parse(mUri));
FaceDetector detector = mRNFaceDetector.getDetector();
detector.process(image).addOnSuccessListener(new OnSuccessListener<List<Face>>() {
@Override
public void onSuccess(List<Face> faces) {
serializeEventData(faces);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
Log.e(ERROR_TAG, "Text recognition task failed", e);
mPromise.reject(ERROR_TAG, "Text recognition task failed", e);
}
});
} catch (IOException e) {
e.printStackTrace();
Log.e(ERROR_TAG, "Creating Firebase Image from uri" + mUri + "failed", e);
mPromise.reject(ERROR_TAG, "Creating Firebase Image from uri" + mUri + "failed", e);
}
return null;
}
use of androidx.exifinterface.media.ExifInterface 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 androidx.exifinterface.media.ExifInterface in project uCrop by Yalantis.
the class ImageHeaderParser method copyExif.
public static void copyExif(ExifInterface originalExif, int width, int height, String imageOutputPath) {
String[] attributes = new String[] { ExifInterface.TAG_F_NUMBER, ExifInterface.TAG_DATETIME, ExifInterface.TAG_DATETIME_DIGITIZED, ExifInterface.TAG_EXPOSURE_TIME, ExifInterface.TAG_FLASH, ExifInterface.TAG_FOCAL_LENGTH, ExifInterface.TAG_GPS_ALTITUDE, ExifInterface.TAG_GPS_ALTITUDE_REF, ExifInterface.TAG_GPS_DATESTAMP, ExifInterface.TAG_GPS_LATITUDE, ExifInterface.TAG_GPS_LATITUDE_REF, ExifInterface.TAG_GPS_LONGITUDE, ExifInterface.TAG_GPS_LONGITUDE_REF, ExifInterface.TAG_GPS_PROCESSING_METHOD, ExifInterface.TAG_GPS_TIMESTAMP, ExifInterface.TAG_PHOTOGRAPHIC_SENSITIVITY, ExifInterface.TAG_MAKE, ExifInterface.TAG_MODEL, ExifInterface.TAG_SUBSEC_TIME, ExifInterface.TAG_SUBSEC_TIME_DIGITIZED, ExifInterface.TAG_SUBSEC_TIME_ORIGINAL, ExifInterface.TAG_WHITE_BALANCE };
try {
ExifInterface newExif = new ExifInterface(imageOutputPath);
String value;
for (String attribute : attributes) {
value = originalExif.getAttribute(attribute);
if (!TextUtils.isEmpty(value)) {
newExif.setAttribute(attribute, value);
}
}
newExif.setAttribute(ExifInterface.TAG_IMAGE_WIDTH, String.valueOf(width));
newExif.setAttribute(ExifInterface.TAG_IMAGE_LENGTH, String.valueOf(height));
newExif.setAttribute(ExifInterface.TAG_ORIENTATION, "0");
newExif.saveAttributes();
} catch (IOException e) {
Log.d(TAG, e.getMessage());
}
}
use of androidx.exifinterface.media.ExifInterface in project android by nextcloud.
the class BitmapUtils method rotateImage.
/**
* Rotate bitmap according to EXIF orientation. Cf. http://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/
*
* @param bitmap Bitmap to be rotated
* @param storagePath Path to source file of bitmap. Needed for EXIF information.
* @return correctly EXIF-rotated bitmap
*/
public static Bitmap rotateImage(Bitmap bitmap, String storagePath) {
Bitmap resultBitmap = bitmap;
try {
ExifInterface exifInterface = new ExifInterface(storagePath);
int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
Matrix matrix = new Matrix();
// 2
if (orientation == ExifInterface.ORIENTATION_FLIP_HORIZONTAL) {
matrix.postScale(-1.0f, 1.0f);
} else // 3
if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
matrix.postRotate(180);
} else // 4
if (orientation == ExifInterface.ORIENTATION_FLIP_VERTICAL) {
matrix.postScale(1.0f, -1.0f);
} else // 5
if (orientation == ExifInterface.ORIENTATION_TRANSPOSE) {
matrix.postRotate(-90);
matrix.postScale(1.0f, -1.0f);
} else // 6
if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
matrix.postRotate(90);
} else // 7
if (orientation == ExifInterface.ORIENTATION_TRANSVERSE) {
matrix.postRotate(90);
matrix.postScale(1.0f, -1.0f);
} else // 8
if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
matrix.postRotate(270);
}
// Rotate the bitmap
resultBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
if (!resultBitmap.equals(bitmap)) {
bitmap.recycle();
}
} catch (Exception exception) {
Log_OC.e("BitmapUtil", "Could not rotate the image: " + storagePath);
}
return resultBitmap;
}
use of androidx.exifinterface.media.ExifInterface in project Signal-Android by signalapp.
the class ZoomingImageView method setSubsamplingImageViewUri.
private void setSubsamplingImageViewUri(@NonNull Uri uri) {
subsamplingImageView.setBitmapDecoderFactory(new AttachmentBitmapDecoderFactory());
subsamplingImageView.setRegionDecoderFactory(new AttachmentRegionDecoderFactory());
subsamplingImageView.setVisibility(View.VISIBLE);
photoView.setVisibility(View.GONE);
// https://github.com/signalapp/Signal-Android/issues/11732#issuecomment-963203545
try {
final InputStream inputStream = PartAuthority.getAttachmentStream(getContext(), uri);
final int orientation = BitmapUtil.getExifOrientation(new ExifInterface(inputStream));
inputStream.close();
if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
subsamplingImageView.setOrientation(SubsamplingScaleImageView.ORIENTATION_90);
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
subsamplingImageView.setOrientation(SubsamplingScaleImageView.ORIENTATION_180);
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
subsamplingImageView.setOrientation(SubsamplingScaleImageView.ORIENTATION_270);
} else {
subsamplingImageView.setOrientation(SubsamplingScaleImageView.ORIENTATION_0);
}
} catch (IOException e) {
Log.w(TAG, e);
}
subsamplingImageView.setImage(ImageSource.uri(uri));
}
Aggregations