Android-纵向模式下的Google Sample HdrViewFinder [英] Android - Google Sample HdrViewFinder in Portrait Mode

查看:228
本文介绍了Android-纵向模式下的Google Sample HdrViewFinder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我解决以下代码吗?我想从Google示例转换HdrViewFinder项目( https://github.com/googlesamples/android -HdrViewfinder ),使其也可以在纵向模式下使用.但是该项目只能在横向模式下工作. 在人像模式下,相机预览会失真.

can somebody help me out with the following code. I want to transform the HdrViewFinder project from google samples (https://github.com/googlesamples/android-HdrViewfinder) so that it also works in portrait mode. But the project works only in landscape mode. In portrait mode, the camera preview gets distorted.

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

So, here is the method I extracted from the HdrViewfinderActivity.java class which I think is responsible for setting the whole view into landscape:

/**
     * 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.但这也无济于事.

How could I change this method so that it works also in portrait mode? What do I need to change ? Setting only the screenOrientation attribute in the manifest file to portrait did not help. I have found out the 16:9 is used for full landscape mode and that 9:16 used for full portrait mode. So, I changed MAX_WIDTH to 720 and TARGET_ASPECT to 9.f/16.f . But that also did not help.

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

Can somebody provide a solution ?

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

Here is a little sketch showing the problem/what happens when I just set the screenOrientation attribute in the manifest file to portrait mode:

推荐答案

我有一个通过从SurfaceView切换到TextureView来实现此目的的实验性分叉.

已在具有 Android Pie

tested on Sony G8441 a.k.a Xperia XZ1 Compact with Android Pie

这篇关于Android-纵向模式下的Google Sample HdrViewFinder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆