【问题标题】:Android - Google Sample HdrViewFinder in Portrait ModeAndroid - 纵向模式下的 Google 示例 HdrViewFinder
【发布时间】:2019-08-29 20:34:07
【问题描述】:

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

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

/**
     * 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 更改为 720TARGET_ASPECT 更改为 9.f/16.f 。但这也无济于事。

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

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

【问题讨论】:

    标签: android android-camera2 aspect-ratio landscape-portrait


    【解决方案1】:

    我有一个experimental fork 可以通过从 SurfaceView 切换到 TextureView 来实现这一点。

    在带有 Android Pie

    的 Sony G8441 又名 Xperia XZ1 Compact 上进行了测试

    【讨论】:

    • 谢谢,您的项目帮了大忙。我研究了一下,我需要的方法是对 TextureView 实例的 setRotation() 调用。
    • 哦,我必须承认我将 HdrViewfinder 项目用于不同的目的。我只是对将 Camera2 API 与 renderscript 结合起来进行图像/视频处理感兴趣。关于使用 camera2 的渲染脚本的项目并不多。 HdrViewfinder 部分并没有让我很感兴趣。所以,我没有测试它。对不起
    • 没关系。我很高兴我的建议能有所帮助。
    猜你喜欢
    • 2017-09-06
    • 2014-03-26
    • 1970-01-01
    • 1970-01-01
    • 2020-01-12
    • 1970-01-01
    • 2012-02-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多