Java Code Examples for androidx.exifinterface.media.ExifInterface#ORIENTATION_TRANSPOSE

The following examples show how to use androidx.exifinterface.media.ExifInterface#ORIENTATION_TRANSPOSE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BitmapUtil.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Nullable
public static Pair<Integer, Integer> getExifDimensions(InputStream inputStream) throws IOException {
  ExifInterface exif   = new ExifInterface(inputStream);
  int           width  = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 0);
  int           height = exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, 0);
  if (width == 0 || height == 0) {
    return null;
  }

  int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0);
  if (orientation == ExifInterface.ORIENTATION_ROTATE_90  ||
      orientation == ExifInterface.ORIENTATION_ROTATE_270 ||
      orientation == ExifInterface.ORIENTATION_TRANSVERSE ||
      orientation == ExifInterface.ORIENTATION_TRANSPOSE)
  {
    return new Pair<>(height, width);
  }
  return new Pair<>(width, height);
}
 
Example 2
Source File: BitmapLoadUtils.java    From EasyPhotos with Apache License 2.0 6 votes vote down vote up
public static int exifToDegrees(int exifOrientation) {
    int rotation;
    switch (exifOrientation) {
        case ExifInterface.ORIENTATION_ROTATE_90:
        case ExifInterface.ORIENTATION_TRANSPOSE:
            rotation = 90;
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
        case ExifInterface.ORIENTATION_FLIP_VERTICAL:
            rotation = 180;
            break;
        case ExifInterface.ORIENTATION_ROTATE_270:
        case ExifInterface.ORIENTATION_TRANSVERSE:
            rotation = 270;
            break;
        default:
            rotation = 0;
    }
    return rotation;
}
 
Example 3
Source File: BitmapLoadUtils.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
public static int exifToDegrees(int exifOrientation) {
    int rotation;
    switch (exifOrientation) {
        case ExifInterface.ORIENTATION_ROTATE_90:
        case ExifInterface.ORIENTATION_TRANSPOSE:
            rotation = 90;
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
        case ExifInterface.ORIENTATION_FLIP_VERTICAL:
            rotation = 180;
            break;
        case ExifInterface.ORIENTATION_ROTATE_270:
        case ExifInterface.ORIENTATION_TRANSVERSE:
            rotation = 270;
            break;
        default:
            rotation = 0;
    }
    return rotation;
}
 
Example 4
Source File: BitmapUtil.java    From deltachat-android with GNU General Public License v3.0 6 votes vote down vote up
@Nullable
public static Pair<Integer, Integer> getExifDimensions(InputStream inputStream) throws IOException {
  ExifInterface exif   = new ExifInterface(inputStream);
  int           width  = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 0);
  int           height = exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, 0);
  if (width == 0 && height == 0) {
    return null;
  }

  int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0);
  if (orientation == ExifInterface.ORIENTATION_ROTATE_90  ||
      orientation == ExifInterface.ORIENTATION_ROTATE_270 ||
      orientation == ExifInterface.ORIENTATION_TRANSVERSE ||
      orientation == ExifInterface.ORIENTATION_TRANSPOSE)
  {
    return new Pair<>(height, width);
  }
  return new Pair<>(width, height);
}
 
Example 5
Source File: CameraUtils.java    From Lassi-Android with MIT License 5 votes vote down vote up
public static int readExifOrientation(int exifOrientation) {
    int orientation;
    switch (exifOrientation) {
        case ExifInterface.ORIENTATION_NORMAL:
        case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
            orientation = 0;
            break;

        case ExifInterface.ORIENTATION_ROTATE_180:
        case ExifInterface.ORIENTATION_FLIP_VERTICAL:
            orientation = 180;
            break;

        case ExifInterface.ORIENTATION_ROTATE_90:
        case ExifInterface.ORIENTATION_TRANSPOSE:
            orientation = 90;
            break;

        case ExifInterface.ORIENTATION_ROTATE_270:
        case ExifInterface.ORIENTATION_TRANSVERSE:
            orientation = 270;
            break;

        default:
            orientation = 0;
    }
    return orientation;
}
 
Example 6
Source File: BitmapLoadUtils.java    From EasyPhotos with Apache License 2.0 5 votes vote down vote up
public static int exifToTranslation(int exifOrientation) {
    int translation;
    switch (exifOrientation) {
        case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
        case ExifInterface.ORIENTATION_FLIP_VERTICAL:
        case ExifInterface.ORIENTATION_TRANSPOSE:
        case ExifInterface.ORIENTATION_TRANSVERSE:
            translation = -1;
            break;
        default:
            translation = 1;
    }
    return translation;
}
 
Example 7
Source File: BitmapLoadUtils.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
public static int exifToTranslation(int exifOrientation) {
    int translation;
    switch (exifOrientation) {
        case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
        case ExifInterface.ORIENTATION_FLIP_VERTICAL:
        case ExifInterface.ORIENTATION_TRANSPOSE:
        case ExifInterface.ORIENTATION_TRANSVERSE:
            translation = -1;
            break;
        default:
            translation = 1;
    }
    return translation;
}
 
Example 8
Source File: ImageHelper.java    From FairEmail with GNU General Public License v3.0 4 votes vote down vote up
static Matrix getImageRotation(File file) {
    try {
        ExifInterface exif = new ExifInterface(file.getAbsolutePath());
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);

        Matrix matrix = new Matrix();
        switch (orientation) {
            case ExifInterface.ORIENTATION_NORMAL:
                return null;
            case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
                matrix.setScale(-1, 1);
                return matrix;
            case ExifInterface.ORIENTATION_FLIP_VERTICAL:
                matrix.setRotate(180);
                matrix.postScale(-1, 1);
                return matrix;
            case ExifInterface.ORIENTATION_TRANSPOSE:
                matrix.setRotate(90);
                matrix.postScale(-1, 1);
                return matrix;
            case ExifInterface.ORIENTATION_TRANSVERSE:
                matrix.setRotate(-90);
                matrix.postScale(-1, 1);
                return matrix;
            case ExifInterface.ORIENTATION_ROTATE_90:
                matrix.setRotate(90);
                return matrix;
            case ExifInterface.ORIENTATION_ROTATE_180:
                matrix.setRotate(180);
                return matrix;
            case ExifInterface.ORIENTATION_ROTATE_270:
                matrix.setRotate(-90);
                return matrix;
            default:
                return null;
        }
    } catch (Throwable ex /* IOException */) {
        /*
            java.lang.RuntimeException: setDataSourceCallback failed: status = 0x80000000
            java.lang.RuntimeException: setDataSourceCallback failed: status = 0x80000000
              at android.media.MediaMetadataRetriever._setDataSource(Native Method)
              at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:226)
              at androidx.exifinterface.media.ExifInterface.getHeifAttributes(SourceFile:5716)
              at androidx.exifinterface.media.ExifInterface.loadAttributes(SourceFile:4556)
              at androidx.exifinterface.media.ExifInterface.initForFilename(SourceFile:5195)
              at androidx.exifinterface.media.ExifInterface.<init>(SourceFile:3926)
         */
        Log.w(ex);
        return null;
    }
}
 
Example 9
Source File: PhotoEditorActivity.java    From react-native-photo-editor with Apache License 2.0 4 votes vote down vote up
private static Bitmap rotateBitmap(Bitmap bitmap, int orientation, boolean reverse) {
    Matrix matrix = new Matrix();

    switch (orientation) {
        case ExifInterface.ORIENTATION_NORMAL:
            return bitmap;
        case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
            matrix.setScale(-1, 1);

            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
            matrix.setRotate(180);

            break;
        case ExifInterface.ORIENTATION_FLIP_VERTICAL:
            matrix.setRotate(180);
            matrix.postScale(-1, 1);

            break;
        case ExifInterface.ORIENTATION_TRANSPOSE:
            if (!reverse) {
                matrix.setRotate(90);
            } else {
                matrix.setRotate(-90);
            }

            matrix.postScale(-1, 1);
            break;
        case ExifInterface.ORIENTATION_ROTATE_90:
            if (!reverse) {
                matrix.setRotate(90);
            } else {
                matrix.setRotate(-90);
            }

            break;
        case ExifInterface.ORIENTATION_TRANSVERSE:
            if (!reverse) {
                matrix.setRotate(-90);
            } else {
                matrix.setRotate(90);
            }

            matrix.postScale(-1, 1);
            break;
        case ExifInterface.ORIENTATION_ROTATE_270:
            if (!reverse) {
                matrix.setRotate(-90);
            } else {
                matrix.setRotate(90);
            }

            break;
        default:
            return bitmap;
    }

    try {
        Bitmap bmRotated = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
        bitmap.recycle();

        return bmRotated;
    } catch (OutOfMemoryError e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 10
Source File: UiUtils.java    From tindroid with Apache License 2.0 4 votes vote down vote up
@NonNull
static Bitmap rotateBitmap(@NonNull Bitmap bmp, int orientation) {
    Matrix matrix = new Matrix();
    switch (orientation) {
        case ExifInterface.ORIENTATION_NORMAL:
            return bmp;
        case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
            matrix.setScale(-1, 1);
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
            matrix.setRotate(180);
            break;
        case ExifInterface.ORIENTATION_FLIP_VERTICAL:
            matrix.setRotate(180);
            matrix.postScale(-1, 1);
            break;
        case ExifInterface.ORIENTATION_TRANSPOSE:
            matrix.setRotate(90);
            matrix.postScale(-1, 1);
            break;
        case ExifInterface.ORIENTATION_ROTATE_90:
            matrix.setRotate(90);
            break;
        case ExifInterface.ORIENTATION_TRANSVERSE:
            matrix.setRotate(-90);
            matrix.postScale(-1, 1);
            break;
        case ExifInterface.ORIENTATION_ROTATE_270:
            matrix.setRotate(-90);
            break;
        default:
            return bmp;
    }

    try {
        Bitmap rotated = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
        bmp.recycle();
        return rotated;
    } catch (OutOfMemoryError ex) {
        Log.e(TAG, "Out of memory while rotating bitmap");
        return bmp;
    }
}