Android Camera2 preview is stretching

4k Views Asked by At

I'm using Camera2 but the preview is stretching. Please help me.I have uploaded images please check. I'm new to android.

From Camera Image From Camera Code I'm using

1

There are 1 best solutions below

3
On

Please take a look at the official sample apps from Google, such as Camera2Basic, or the new CameraView library. They handle aspect ratio issues such as what you're seeing.

Edit:

As of 2023, I'd recommend looking at the CameraX CameraViewfinder class if you're wanting to use camera2 directly. It handles picking between TextureView and SurfaceView based on API level and device quirks, and deals with aspect ratios and rotations correctly.

If you're using CameraX for the whole camera experience, then the CameraX PreviewView is even simpler to use.