显示在Android

时间:2018-04-13 01:32:58

标签: android android-studio android-camera orientation image-capture

我正在尝试使用Camera View lib

制作相机拍摄的图像

不幸的是,lib不支持像三星这样的设备中的图像旋转问题。

经过长时间的搜索,我发现我可以通过获取像this&的旋转值来修复它。 this 但它没有解决我的问题。

我需要的是用户在任何模式下捕获图像(默认纵向 - 默认 风景 - 其他 横向 - 其他肖像)显示为。

这是获取方向的代码。

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;
    }

这是设置旋转的代码

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);

    }

希望得到任何人的帮助

  

编辑1: showImage()方法工作以显示旋转   mCapturedImageCopy

0 个答案:

没有答案