Skip to content Skip to sidebar Skip to footer

Android Java.lang.illegalargumentexception: Previewsize Must Not Be Taller Than Activearray

My application was working good in large number of phones. However, when I installed it in my old android phone the following error is thrown and application crashes while taking t

Solution 1:

Based on the code found here, its pretty self explanatory that the old device preview size is less than the size that you're trying to crop.

Check the getPreviewCropRectangleUnzoomed function in the code that I have mentioned above. The documentation of the function says the cause of the error specifically. From the documentation.

/**
 * Calculate the effective crop rectangle for this preview viewport;
 * assumes the preview is centered to the sensor and scaled to fit across one of the dimensions
 * without skewing.
 *
 * <p>The preview size must be a subset of the active array size; the resulting
 * rectangle will also be a subset of the active array rectangle.</p>
 *
 * <p>The unzoomed crop rectangle is calculated only.</p>
 *
 * @param activeArray active array dimensions, in sensor space
 * @param previewSize size of the preview buffer render target, in pixels (not in sensor space)
 * @return a rectangle which serves as the preview stream's effective crop region (unzoomed),
 *         in sensor space
 *
 * @throws NullPointerException
 *          if any of the args were {@code null}
 * @throws IllegalArgumentException
 *          if {@code previewSize} is wider or taller than {@code activeArray}
 */

Check the part - The preview size must be a subset of the active array size; the resulting rectangle will also be a subset of the active array rectangle. which declares the preview size must be smaller than the actual active array size.

In this case, you might consider having a try/catch block while you are taking picture using the camera.

try {
    takePicture();
} catch (IllegalArgumentException e) {
    Toast.makeText(this, "Your phone is too old", Toast.LENGTH_SHORT).show();
}

Hope that helps.

Solution 2:

I believe that this may happen in very old devices with small image sensors, although seems to me (only guessing) more like a mistake by the manufacturer when they implemented the camera2 legacy wrapper.

A solution could be that when you are resolving the optimal preview size, then also to take into account that such preview size it doesn't exceed the size specified by SENSOR_INFO_ACTIVE_ARRAY_SIZE, which can be queried in the CameraCharacteristics:

CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE

Post a Comment for "Android Java.lang.illegalargumentexception: Previewsize Must Not Be Taller Than Activearray"