Search in sources :

Example 11 with ExifInterface

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;
}
Also used : RNFaceDetector(org.reactnative.facedetector.RNFaceDetector) FaceDetector(com.google.mlkit.vision.face.FaceDetector) ExifInterface(androidx.exifinterface.media.ExifInterface) List(java.util.List) IOException(java.io.IOException) Face(com.google.mlkit.vision.face.Face) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) InputImage(com.google.mlkit.vision.common.InputImage) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) IOException(java.io.IOException)

Example 12 with ExifInterface

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);
    }
}
Also used : ExifSubIFDDirectory(com.drew.metadata.exif.ExifSubIFDDirectory) ImageProcessingException(com.drew.imaging.ImageProcessingException) FileOutputStream(java.io.FileOutputStream) ExifInterface(androidx.exifinterface.media.ExifInterface) Tag(com.drew.metadata.Tag) IOException(java.io.IOException) ExifSubIFDDirectory(com.drew.metadata.exif.ExifSubIFDDirectory) Directory(com.drew.metadata.Directory) ExifIFD0Directory(com.drew.metadata.exif.ExifIFD0Directory)

Example 13 with ExifInterface

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());
    }
}
Also used : ExifInterface(androidx.exifinterface.media.ExifInterface) IOException(java.io.IOException)

Example 14 with ExifInterface

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;
}
Also used : Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) ExifInterface(androidx.exifinterface.media.ExifInterface) Paint(android.graphics.Paint) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 15 with ExifInterface

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));
}
Also used : InputStream(java.io.InputStream) ExifInterface(androidx.exifinterface.media.ExifInterface) IOException(java.io.IOException) SuppressLint(android.annotation.SuppressLint)

Aggregations

ExifInterface (androidx.exifinterface.media.ExifInterface)15 IOException (java.io.IOException)10 InputStream (java.io.InputStream)5 Paint (android.graphics.Paint)4 Bitmap (android.graphics.Bitmap)3 FileNotFoundException (java.io.FileNotFoundException)3 SuppressLint (android.annotation.SuppressLint)2 Cursor (android.database.Cursor)2 Point (android.graphics.Point)2 Pair (android.util.Pair)2 AnyThread (androidx.annotation.AnyThread)2 WorkerThread (androidx.annotation.WorkerThread)2 GifDrawable (com.bumptech.glide.load.resource.gif.GifDrawable)2 FileOutputStream (java.io.FileOutputStream)2 ExecutionException (java.util.concurrent.ExecutionException)2 DecryptableUri (org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri)2 Resources (android.content.res.Resources)1 BitmapFactory (android.graphics.BitmapFactory)1 Matrix (android.graphics.Matrix)1 ImageProcessingException (com.drew.imaging.ImageProcessingException)1