Android - Google 纵向模式下的 HdrViewFinder 示例

Android - Google Sample HdrViewFinder in Portrait Mode

有人可以用以下代码帮助我吗?我想从 google 个示例 (https://github.com/googlesamples/android-HdrViewfinder) 转换 HdrViewFinder 项目,以便它也可以在纵向模式下工作。但该项目仅适用于横向模式。 在纵向模式下,相机预览会失真。

所以,这是我从 HdrViewfinderActivity.java class 中提取的方法,我认为它负责将整个视图设置为横向:

/**
     * Configure the surfaceview and RS processing.
     */
    private void configureSurfaces() {
        // Find a good size for output - largest 16:9 aspect ratio that's less than 720p
        final int MAX_WIDTH = 1280;
        final float TARGET_ASPECT = 16.f / 9.f;
        final float ASPECT_TOLERANCE = 0.1f;

        StreamConfigurationMap configs =
                mCameraInfo.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
        if (configs == null) {
            throw new RuntimeException("Cannot get available picture/preview sizes.");
        }
        Size[] outputSizes = configs.getOutputSizes(SurfaceHolder.class);

        Size outputSize = outputSizes[0];
        float outputAspect = (float) outputSize.getWidth() / outputSize.getHeight();
        for (Size candidateSize : outputSizes) {
            if (candidateSize.getWidth() > MAX_WIDTH) continue;
            float candidateAspect = (float) candidateSize.getWidth() / candidateSize.getHeight();
            boolean goodCandidateAspect =
                    Math.abs(candidateAspect - TARGET_ASPECT) < ASPECT_TOLERANCE;
            boolean goodOutputAspect =
                    Math.abs(outputAspect - TARGET_ASPECT) < ASPECT_TOLERANCE;
            if ((goodCandidateAspect && !goodOutputAspect) ||
                    candidateSize.getWidth() > outputSize.getWidth()) {
                outputSize = candidateSize;
                outputAspect = candidateAspect;
            }
        }
        Log.i(TAG, "Resolution chosen: " + outputSize);

        // Configure processing
        mProcessor = new ViewfinderProcessor(mRS, outputSize);
        setupProcessor();

        // Configure the output view - this will fire surfaceChanged
        mPreviewView.setAspectRatio(outputAspect);
        mPreviewView.getHolder().setFixedSize(outputSize.getWidth(), outputSize.getHeight());
}

如何更改此方法,使其在纵向模式下也能正常工作?我需要改变什么? 仅将清单文件中的 screenOrientation 属性设置为 portrait 没有帮助。 我发现 16:9 用于全横向模式,而 9:16 用于全纵向模式。因此,我将 MAX_WIDTH 更改为 720 并将 TARGET_ASPECT 更改为 9.f/16.f 。但这也无济于事。

有人可以提供解决方案吗?

这是一个小草图,显示了当我将清单文件中的 screenOrientation 属性设置为纵向模式时发生的 problem/what:

我有一个 experimental fork 可以实现这一点,方法是从 SurfaceView 切换到 TextureView。

在索尼 G8441 上测试 a.k.a Xperia XZ1 Compact with Android Pie