1

我正在构建一个关于 camera2video API 的应用程序。想要显示预览全屏,但它占据了屏幕的 70% 区域,如 Camera2video API Github https://github.com/googlesamples/android-Camera2Video所示, 而且视频质量参数也没有选项它在已弃用的 Camera API 中可用。

4

3 回答 3

1

Camera2Video演示包含一个名为的类,该类AutoFitTextureView在保留纵横比的同时适合纹理视图内的预览。如果要拉伸预览以填满整个屏幕,只需使用常规TextureView而不是此类。

您需要替换类AutoFitTextureView中的引用Camera2VideoFragment,以及纵向和横向的布局 XML 文件中的引用。layout_width将和更改layout_heightmatch_parent

并且视频质量参数也没有选项,因为它在已弃用的相机 API 中可用

将其设置在MediaRecorder对象 ( mMediaRecorder) 中Camera2VideoFragment

于 2016-05-31T07:44:06.300 回答
1

camera2 工具不太好。在您的情况下,您可以找到方法chooseVideoSize并通过以下方式进行更改:

private Size chooseVideoSize(Size[] choices) {

        for (Size size : choices) {
            if (size.getWidth() == size.getHeight() * 16 / 9 && size.getWidth() <= 1080) {
                return size;
            }
        }
        Log.e(TAG, "Couldn't find any suitable video size");
        return choices[choices.length - 1];
    }

接下来,您应该将android:layout_alignParentEnd="true"插入到默认布局文件夹的 fragment_camera2_video.xml 中。看起来像:

<com.example.android.camera2video.AutoFitTextureView
        android:id="@+id/texture"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentEnd="true" //add here
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true" />
于 2016-11-18T07:13:34.800 回答
1
int width = MeasureSpec.getSize(widthMeasureSpec);
    int height = MeasureSpec.getSize(heightMeasureSpec);
    if (0 == mRatioWidth || 0 == mRatioHeight) {
        setMeasuredDimension(width, height);
    } else {
        if (width < height * mRatioWidth / mRatioHeight) {
            setMeasuredDimension(height * mRatioWidth / mRatioHeight, height);
        } else {
            setMeasuredDimension(width, width * mRatioHeight / mRatioWidth);
        }
    }

在 onMeasure 方法的 AutoFitTextureview 类中更改它

于 2018-02-13T07:28:06.677 回答