Search code examples
androidandroid-cameragalaxy

Issue with Samsung Galaxy SIII - Camera.onPictureTaken() returning interlaced image instead of proper capture image


We have an application that utilizes the rear 'Camera' to capture item image. So far all devices that we have tested are all working correctly in term of capturing image as it should be, until Samsung Galaxy SIII (S3).

On Samsung Galaxy SIII only, we are observing that Camera.onPictureTaken() is returning an raw image appears to interlaced instead of proper capture image. Debugging each of camera parameter setting, determine that the following parameter setter is causing the issue. If we don't explicitly setPictureSize() on parameter, then it is working as expected:

parameters.setPictureSize(targetPictureSize);  

By default parameters.getPictureSize() return as [w,h]=[3264, 2448]

The 'targetPictureSize' is determined base on closest matching Size return from below, in this case, we have used the [w,h]=[1600, 1200] size as the 'targetPictureSize'

camera.getParameters().getSupportedPictureSizes();

Anyone know the reason and a workaround?


Solution

  • This issue appears to happen when you call camera.setParameters with a different pictureSize than what was configured previously (or the default value), while the preview is active. The solution is to ether set the picture size before starting the preview or stopping the preview, setting the parameters, and then restarting the preview.

    parameters.setPictureSize(1600, 1200);
    ...
    camera.stopPreview();
    camera.setParameters(parameters);
    camera.startPreview();
    

    Technical Note:

    The cause of the interlacing appears to be that the image returned from the camera is captured at the default resolution (3264x2448), but is marked as the resolution you specified with setPictureSize. As a result, when such image is being displayed, every row of pixels from the captured image is being displayed as (default resolution / specified resolution) rows of pixels. With picture size of 1600x1200 this will result in the image appearing interlaced, while at other resolutions (ex. 640x480) the image will appear completely corrupted.