全屏预览相机2基本示例项目 [英] Full screen preview camera2Basic Example Project

查看:143
本文介绍了全屏预览相机2基本示例项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试修改Google的 camera2Basic 示例代码.我删除了包含图片"和信息"按钮的<FrameLayout/>,试图使<TextureView/>全屏显示.但是,预览不能填满整个屏幕,在其下方仍然有一个黑条.我相信这与它附带的AutoFitTextureView有关,但是由于他们没有提供有关其工作方式的任何文档,所以我无法对其进行修改.

I'm trying to modify Google's camera2Basic example code. I removed the <FrameLayout/> containing the "Picture" and "Info" button in an attempt to make the <TextureView/> full screen. However, the preview does not fill the entire screen, there remains a black bar below it. I believe this has something to do with the AutoFitTextureView that it ships with but since they haven't provided any documentation on how it works I am unable to make modifications to it.

推荐答案

我之前在我的Galaxy Note 5上注意到了这个完全相同的问题,并且我相信这与它们设置长宽比的方式有关-显然存在一些局限性使用此API(或文献记载不充分).我没有在AutoFitTextureView上设置宽高比来解决此问题.

I noticed this exact same issue before on my Galaxy Note 5 and I believe it had to do with the way they set the aspect ratio - there are apparently some limitations with this API (or just poorly documented). I fixed it by not setting the aspect ratio on the AutoFitTextureView.

特别是在此示例中,在setCameraOutput(int width,int height)方法中,只需删除以下代码行(在您的示例中为574-580行):

Specifically in this example, in the method setCameraOutput(int width, int height), simply remove these lines of code (lines 574 - 580 in your example):

if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
    mTextureView.setAspectRatio(mPreviewSize.getWidth(),mPreviewSize.getHeight());
} else {
    mTextureView.setAspectRatio(mPreviewSize.getHeight(),mPreviewSize.getWidth());
}

我相信在该示例中,他们试图限制捕获区域,这有可能导致您看到黑条(可能是因为您使用的设备比开发人员所使用的设备大).

I believe that in the example they are trying to limit the capture area which likely leads to the black bar you are seeing (probably because you are building on a larger device than the one the person who developed used).

这篇关于全屏预览相机2基本示例项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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