How to get Android Camera Preview ratio 1:1

android, android-layout, camera

Solution

As you have noticed, camera preview frames are 4:3. Often, you can also setPreviewSize() to have aspect ratio ~9:4 (e.g. 800x480). I have not encountered an Android device that will have a square among getSupportedPreviewSizes().

Your options to display a square preview are as follows: overlay the preview SurfaceView with non-transparent margins ontwo sides (effectively cropping the look). Or you could crop the image while displaying the TextureSurface through OpenGL. Or you could setPreviewCallbackWithBuffer(), crop the yuv frame to your desired size, and display it (prefferably, through OpenGL).

Problem

I am trying to implement the a Android camera preview and want to have it display in 1:1 ratio (just like the Instagram camera). I know how to deal with the preview frame size to be 1:1, but the camera output shows on the preview is squeezed. It looks like the live preview is still in 4:3 ratio but is squeezed to 1:1 frame. Is there a way to have the live preview also in 1:1 ratio? I am not pasting any code here because I have tried many approach but all failed, nothing I can post... Thank you

Original source