0

I'm trying to make Image captured by the camera by using Camera View lib

Unfortunately, the lib does not support the issue of image rotation in some devices like Samsung.

after long of search, I found out that I can fix it by getting the rotated value like this & this but It not solved my issue.

what I need is if user captured Image in any mode (Default Portrait- Default Landscape- Other Landscape- Other Portrait) is displayed as it.

this is code for getting orientation.

private int getRightRotationAngel(byte[] data) {

        ExifInterface exifInterface;
        try {
            exifInterface = new ExifInterface(new ByteArrayInputStream(data));
        } catch (IOException e) {
            e.printStackTrace();
            return 0;
        }
        int orientation;
        int rotationDegrees = 0;
        orientation = exifInterface.getAttributeInt
                (ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);

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

        }
        return rotationDegrees;
    }

this is code for setting rotation

private void setImageInCorrectRotation(byte[] data) {
        int rotateDegree = getRightRotationAngel(data);
        Matrix matrix = new Matrix();

        Toast.makeText(FrameViewerActivity.this, rotateDegree + "", Toast.LENGTH_SHORT).show();
        if (rotateDegree != 0)
            matrix.postRotate(rotateDegree);

        mCapturedImageCopy = Bitmap.createBitmap(mCapturedImageCopy, 0, 0,
                mCapturedImageCopy.getWidth(), mCapturedImageCopy.getHeight(), matrix, true);
        showImage(mCapturedImageCopy);

    }

hope to get help from anyone

Edit 1: showImage() method work to display the rotated mCapturedImageCopy

Moustafa EL-Saghier
  • 1,721
  • 1
  • 13
  • 43
  • What goes wrong on your Samsung device? Does it report wrong **exifInterface**? – Alex Cohn Apr 13 '18 at 04:15
  • I don't know if it wrong or not but when I display value got by ExifInterface if get Other portrait/ code 90: view rotated 180 Default landscape/ code 0: view rotated 90 Other landscape/ code 180: view rotated 90 – Moustafa EL-Saghier Apr 13 '18 at 12:36

0 Answers0