Full screen preview camera2Basic Example Project

2019-01-15 22:19发布

问题:

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