Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
810 views
in Technique[技术] by (71.8m points)

android - Full screen preview camera2Basic Example Project

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...