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

The following examples show how to use androidx.exifinterface.media.ExifInterface#ORIENTATION_ROTATE_180 . 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: BitmapUtils.java    From Lassi-Android with MIT License 6 votes vote down vote up
/**
 * Rotate the given image by given Exif value.<br>
 * If no rotation is required the image will not be rotated.<br>
 * New bitmap is created and the old one is recycled.
 */
static RotateBitmapResult rotateBitmapByExif(Bitmap bitmap, ExifInterface exif) {
    int degrees;
    int orientation =
            exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
    switch (orientation) {
        case ExifInterface.ORIENTATION_ROTATE_90:
            degrees = 90;
            break;
        case ExifInterface.ORIENTATION_ROTATE_180:
            degrees = 180;
            break;
        case ExifInterface.ORIENTATION_ROTATE_270:
            degrees = 270;
            break;
        default:
            degrees = 0;
            break;
    }
    return new RotateBitmapResult(bitmap, degrees);
}
 
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: BitmapUtils.java    From leafpicrevived with GNU General Public License v3.0 6 votes vote down vote up
public static int getOrientation(Uri uri, Context ctx) {

        try (InputStream in = ctx.getContentResolver().openInputStream(uri)) {
            if (in == null) {
                return 0;
            }
            ExifInterface exif = new ExifInterface(in);
            int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);

            switch (orientation) {
                case ExifInterface.ORIENTATION_ROTATE_180:
                    return SubsamplingScaleImageView.ORIENTATION_180;
                case ExifInterface.ORIENTATION_ROTATE_90:
                    return SubsamplingScaleImageView.ORIENTATION_90;
                case ExifInterface.ORIENTATION_ROTATE_270:
                    return SubsamplingScaleImageView.ORIENTATION_270;
                default:
                    return SubsamplingScaleImageView.ORIENTATION_0;
            }
        } catch (IOException e) {
            return 0;
        }
    }
 
Example 4
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 5
Source File: BitmapHelper.java    From libcommon with Apache License 2.0 6 votes vote down vote up
private static int getOrientation(@NonNull final ExifInterface exif) {
	final int rotation = exif.getAttributeInt(
		ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);

	int result;
	switch (rotation) {
	case ExifInterface.ORIENTATION_ROTATE_90:
		result = 90;
		break;
	case ExifInterface.ORIENTATION_ROTATE_180:
		result = 180;
		break;
	case ExifInterface.ORIENTATION_ROTATE_270:
		result = 270;
		break;
	case ExifInterface.ORIENTATION_UNDEFINED:
	default:
		result = 0;
		break;
	}
	if (DEBUG) Log.v(TAG, "getOrientation:" + result);
	return result;
}
 
Example 6
Source File: BitmapUtils.java    From Android-Image-Cropper with Apache License 2.0 6 votes vote down vote up
/**
 * Rotate the given image by given Exif value.<br>
 * If no rotation is required the image will not be rotated.<br>
 * New bitmap is created and the old one is recycled.
 */
static RotateBitmapResult rotateBitmapByExif(Bitmap bitmap, ExifInterface exif) {
  int degrees;
  int orientation =
      exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
  switch (orientation) {
    case ExifInterface.ORIENTATION_ROTATE_90:
      degrees = 90;
      break;
    case ExifInterface.ORIENTATION_ROTATE_180:
      degrees = 180;
      break;
    case ExifInterface.ORIENTATION_ROTATE_270:
      degrees = 270;
      break;
    default:
      degrees = 0;
      break;
  }
  return new RotateBitmapResult(bitmap, degrees);
}
 
Example 7
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 8
Source File: AppTools.java    From SSForms with GNU General Public License v3.0 5 votes vote down vote up
public int getCameraPhotoOrientation(Uri imageUri){
    int rotate = 0;
    try {
        File imageFile = new File(imageUri.getPath());

        ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

        switch (orientation) {
            case ExifInterface.ORIENTATION_ROTATE_270:
                rotate = 270;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                rotate = 180;
                break;
            case ExifInterface.ORIENTATION_ROTATE_90:
                rotate = 90;
                break;
        }

        Log.i("RotateImage", "Exif orientation: " + orientation);
        Log.i("RotateImage", "Rotate value: " + rotate);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return rotate;
}
 
Example 9
Source File: DrawableProvider.java    From MVPArms with Apache License 2.0 5 votes vote down vote up
/**
 * 读取图片的旋转的角度
 *
 * @param path 图片绝对路径
 * @return 图片的旋转角度
 */
public static int getBitmapDegree(String path) {
    int degree = 0;
    try {
        // 从指定路径下读取图片,并获取其EXIF信息
        ExifInterface exifInterface = new ExifInterface(path);
        // 获取图片的旋转信息
        int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_NORMAL);
        switch (orientation) {
            case ExifInterface.ORIENTATION_ROTATE_90:
                degree = 90;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                degree = 180;
                break;
            case ExifInterface.ORIENTATION_ROTATE_270:
                degree = 270;
                break;
            default:
                break;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return degree;
}
 
Example 10
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 11
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 12
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;
    }
}
 
Example 13
Source File: CameraActivity.java    From cordova-plugin-camera-preview with MIT License 4 votes vote down vote up
private static int exifToDegrees(int exifOrientation) {
  if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) { return 90; }
  else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) {  return 180; }
  else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) {  return 270; }
  return 0;
}
 
Example 14
Source File: ImageUpdater.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == 13) {
            PhotoViewer.getInstance().setParentActivity(parentFragment.getParentActivity());
            int orientation = 0;
            try {
                ExifInterface ei = new ExifInterface(currentPicturePath);
                int exif = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
                switch (exif) {
                    case ExifInterface.ORIENTATION_ROTATE_90:
                        orientation = 90;
                        break;
                    case ExifInterface.ORIENTATION_ROTATE_180:
                        orientation = 180;
                        break;
                    case ExifInterface.ORIENTATION_ROTATE_270:
                        orientation = 270;
                        break;
                }
            } catch (Exception e) {
                FileLog.e(e);
            }
            final ArrayList<Object> arrayList = new ArrayList<>();
            arrayList.add(new MediaController.PhotoEntry(0, 0, 0, currentPicturePath, orientation, false, 0, 0, 0));
            PhotoViewer.getInstance().openPhotoForSelect(arrayList, 0, PhotoViewer.SELECT_TYPE_AVATAR, false, new PhotoViewer.EmptyPhotoViewerProvider() {
                @Override
                public void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo, boolean notify, int scheduleDate) {
                    String path = null;
                    MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) arrayList.get(0);
                    if (photoEntry.imagePath != null) {
                        path = photoEntry.imagePath;
                    } else if (photoEntry.path != null) {
                        path = photoEntry.path;
                    }
                    Bitmap bitmap = ImageLoader.loadBitmap(path, null, 800, 800, true);
                    processBitmap(bitmap);
                }

                @Override
                public boolean allowCaption() {
                    return false;
                }

                @Override
                public boolean canScrollAway() {
                    return false;
                }
            }, null);
            AndroidUtilities.addMediaToGallery(currentPicturePath);
            currentPicturePath = null;
        } else if (requestCode == 14) {
            if (data == null || data.getData() == null) {
                return;
            }
            startCrop(null, data.getData());
        }
    }
}
 
Example 15
Source File: ImageUpdater.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == 13) {
            PhotoViewer.getInstance().setParentActivity(parentFragment.getParentActivity());
            int orientation = 0;
            try {
                ExifInterface ei = new ExifInterface(currentPicturePath);
                int exif = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
                switch (exif) {
                    case ExifInterface.ORIENTATION_ROTATE_90:
                        orientation = 90;
                        break;
                    case ExifInterface.ORIENTATION_ROTATE_180:
                        orientation = 180;
                        break;
                    case ExifInterface.ORIENTATION_ROTATE_270:
                        orientation = 270;
                        break;
                }
            } catch (Exception e) {
                FileLog.e(e);
            }
            final ArrayList<Object> arrayList = new ArrayList<>();
            arrayList.add(new MediaController.PhotoEntry(0, 0, 0, currentPicturePath, orientation, false, 0, 0, 0));
            PhotoViewer.getInstance().openPhotoForSelect(arrayList, 0, PhotoViewer.SELECT_TYPE_AVATAR, false, new PhotoViewer.EmptyPhotoViewerProvider() {
                @Override
                public void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo, boolean notify, int scheduleDate) {
                    String path = null;
                    MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) arrayList.get(0);
                    if (photoEntry.imagePath != null) {
                        path = photoEntry.imagePath;
                    } else if (photoEntry.path != null) {
                        path = photoEntry.path;
                    }
                    Bitmap bitmap = ImageLoader.loadBitmap(path, null, 800, 800, true);
                    processBitmap(bitmap);
                }

                @Override
                public boolean allowCaption() {
                    return false;
                }

                @Override
                public boolean canScrollAway() {
                    return false;
                }
            }, null);
            AndroidUtilities.addMediaToGallery(currentPicturePath);
            currentPicturePath = null;
        } else if (requestCode == 14) {
            if (data == null || data.getData() == null) {
                return;
            }
            startCrop(null, data.getData());
        }
    }
}