全屏预览camera2基本示例工程 [英] Full screen preview camera2Basic Example Project
问题描述
我正在尝试修改 Google 的 camera2Basic 示例代码.我删除了包含图片"和信息"按钮的
以尝试使
全屏显示.但是,预览并没有填满整个屏幕,它下面还有一个黑条.我相信这与它附带的 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).
这篇关于全屏预览camera2基本示例工程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!