Android camera preview stretched/squashed

I had a problem with Samsung Galaxy Xcover 3 when i trying to take a full screen picture via app but the camera preview were squashed from the sides or stretched vertically and the result picture was too.

Cause: Preview size (width/height) is greater than the max support preview size

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
     final int width = resolveSize(getSuggestedMinimumWidth(), widthMeasureSpec);
     final int height = resolveSize(getSuggestedMinimumHeight(), heightMeasureSpec);

     // supported preview sizes
     mSupportedPreviewSizes = mCamera.getParameters().getSupportedPreviewSizes();
     setMeasuredDimension(width, height); 

In “onMeasure” method if width/height is higher than the max supported preview size then you will get stretched/squashed picture.

if we go back to xcover 3 camera spec is (480 x 800) but highest support preview is (480 x  640) and i my case in “onMeasure” method i was getting height of 764 which caused the picture to be squashed from the sides. Setting the height to 640 will result in normal image but the preview window will look as if it cut from the bottom since it will not cover the full screen. But if you check the built in camera preview you will see it does not cover full screen and its cut from the bottom too with the on screen buttons.


Leave a reply