Full screen preview camera2Basic Example Project

╄→гoц情女王★ 提交于 2019-11-28 11:29:40

问题


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.


回答1:


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.

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).



来源:https://stackoverflow.com/questions/41732005/full-screen-preview-camera2basic-example-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!