Issue with Samsung Galaxy SIII - Camera.onPictureT

2019-04-02 08:24发布

问题:

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?

回答1:

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.



回答2:

I suppose there is not going to a good answer or reason for this. I can only fault Samsung for not properly implement Camera.getParameters().setPictureSize().

Below is my workaround by checking for S3 model name and not call setPictureSize()

       // Source - http://en.wikipedia.org/wiki/Samsung_Galaxy_S_III
       String s3ModelNames[] = { "XXXXXXXXXXXXXXXX", // Place holder
                "SAMSUNG-SGH-I747", // AT&T
                "SAMSUNG-SGH-T999", // T-Mobile
                "SAMSUNG-SGH-N064", // Japan
                "SAMSUNG-SCH-R530", // US Cellular
                "SAMSUNG-SCH-I535", // Verizon
                "SAMSUNG-SPH-L710", // Sprint
                "SAMSUNG-GT-I9300", // International
                "SGH-I747", // AT&T
                "SGH-T999", // T-Mobile
                "SGH-N064", // Japan
                "SCH-R530", // US Cellular
                "SCH-I535", // Verizon
                "SPH-L710", // Sprint
                "GT-I9300"  // International
       };

       List<String> s3ModelList = Arrays.asList(s3ModelNames);

       if (s3ModelList.contains(deviceModel)) {
          // DEVICE SPECIFIC WORK AROUND for Samsung Galaxy S3
          // SKIP calling parameters.setPictureSize() Samsung Galaxy SIII phone (Confirmed on AT&T, Verizon, Sprint) due the Camera image are interlaced when setPictureSize() are set to other than default.
       }