I'm trying to learn Camera2 API and I have built a simple camera app just for taking pictures but the problem that I'm facing is that the preview is stretched for some resolutions. I went through a number of different posts and all them suggested that my aspect ratio might be wrong but I have used google's recommended AutoFitTextureView with the correct aspect ratio still my preview is stretched. I downloaded some open source camera apps from playstore and a bunch of them also had the same issue with my front camera(EXCEPT OPEN CAMERA) but the funny part is I used my same app in another device and the preview was absolutely perfect. So finally I decided to test my app with different resolutions and observe the results but I couldn't find any pattern can anyone please help me to make some sense out of it???
my device display size is 720x1280
Front camera results:
SurfaceTexture AutoFitTextureView Result
buffer size size
2576x1932 720x960 Normal
2560x1440 720x1280 Normal
2048x1536 720x960 Normal
2048x1152 720x1280 Normal
1920x1920 720x720 Normal
1920x1080 720x1280 Normal
1440x1080 720x960 Horizontally Stretched
1280x720 720x1280 Horizontally Stretched
1072x1072 720x720 Normal
960x720 720x960 Normal
720x480 720x1080 Horizontally Stretched
640x480 720x960 Horizontally Stretched
352x288 720x880 Normal
320x240 720x960 Normal
256x144 720x1280 Horizontally Stretched
176x144 720x880 Normal
Camera2 is very hard to learn as a beginner. Consider using camera libraries that does the most parts. Here is one which is the best that I have found : https://camerakit.io/docs. It's really easy and it will take care all of the problems that you are facing right now.
(Note that I do not own this project and I am not promoting it in anyway. I have tried camera2 API and it really is hard, which is why I suggested an easier solution.