Android Camera 2 how to crop preview size

I am working on Camera 2 API recently, and my device has a 16: 9 screen ratio, but my camera sensor is 4: 3. So the whole preview size I received is 4: 3. I wonder if there is Is there any way to get grain size and display only 16: 9 part? I tried a lot of time and did not find any help for camera 2.

My current camera code is similar to the base camera 2 sample .

So, how do I crop a preview and display only part 16: 9 on the texture?

Thanks!!

+4
source share
2 answers

SurfaceTexture 4: 3 16: 9.

ConstraintLayout 16: 9 ( ).

, :

texture.setDefaultBufferSize(width, height)

, , .

,

0

setUpCameraOutputs(int width, int height)   ,

// Danger, W.R.! Attempting to use too large a preview size could  exceed the camera
// bus' bandwidth limitation, resulting in gorgeous previews but the storage of
// garbage capture data.
mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), rotatedPreviewWidth, 
rotatedPreviewHeight, maxPreviewWidth, maxPreviewHeight, largest);

, - .

0

Source: https://habr.com/ru/post/1617101/


All Articles