palanceli / android-Camera2Basic

Apache License 2.0
0 stars 0 forks source link

如何实现转屏 #2

Open palanceli opened 6 years ago

palanceli commented 6 years ago

这个demo默认是横屏的,不管手机的实际方向如何,预览图总是一幅横向图: screenshot_1514121480

修改Camera2BasicFragment.java中的configureTransform(...)函数,该函数用于设置textureView的变换矩阵,其中就包括旋转,我在源代码的基础上添加了逆时针旋转90°

    private void configureTransform(int viewWidth, int viewHeight) {
        Activity activity = getActivity();
        ...
        int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
        Matrix matrix = new Matrix();
        ...
        matrix.postRotate(-90, centerX, centerY); // 改成竖屏显示
        mTextureView.setTransform(matrix);
    }

运行后如下: screenshot_1514121525