1

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.

Carpetfizz
  • 8,707
  • 22
  • 85
  • 146

1 Answers1

2

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

ucsunil
  • 7,378
  • 1
  • 27
  • 32
  • That did the trick, thank you! Does that mean this won't work on every device? – Carpetfizz Jan 19 '17 at 01:33
  • 1
    I don't think the API itself is limited by the device - it's the way that they calculate and assume the aspect ratio (where they assume the 1920*1080 resolution) that leads you to believe this. This is a guess from my end as I did not test it. But since it worked for you as well, I would say that my hunch is right – ucsunil Jan 19 '17 at 19:01
  • hey, when I do this, the preview frame is stretched and skewed – Carpetfizz Mar 16 '17 at 16:07
  • Do you know the aspect ratio you are trying to use? And does the black bar appear both below and to the right of the preview area? – ucsunil Mar 16 '17 at 20:26
  • Thanks for the reply. I'm trying to use 16:9 but it's stretching the 4:3. There's no black bars – Carpetfizz Mar 16 '17 at 20:48
  • Can you try setting the aspect ratio explicitly like mTextureView.setAspectRatio(16, 9); or something like that where you directly hardcode the aspect ratio (this may not be a scalable solution for different aspect ratios) - the problem is the documentation is so limited, I'm going off of guesses. Besides different vendors implement cameras differently - can you tell me what your device is and what screensize? – ucsunil Mar 17 '17 at 20:55
  • But it's fixing my preview to `1280x720`. I'm using a `1920x1080` Google Pixel – Carpetfizz Mar 20 '17 at 23:01
  • @Carpetfizz were you able to achieve full screen preview without stretching? – varunkr May 15 '18 at 10:19
  • You should be able to get the preview without stretching. At least I was able to. You may have to play around with aspect ratios to see what works for your phone. I recently noticed that the documentation is still a little poor in this area. – ucsunil May 15 '18 at 20:39