android: camera metering not work in some devices

129 views Asked by At

I need to metering in living broadcast, code below works properly in some devices (Vivo, oppo), but metering does not work in some device(Samsung and Meitu), how to metering in those devices?

Here is my code (handleMetering is called when screen is touched):

   private void setMeteringParam() {
    synchronized (mCameraLock) {
        Camera.Parameters params = mMasterCamera.getParameters();
        if (params.getMaxNumMeteringAreas() > 0) {
            List<Camera.Area> meteringAreas = new ArrayList<>();
            meteringAreas.add(new Camera.Area(mMeteringRect, 800)); //100%
            params.setMeteringAreas(meteringAreas);
            params.setMeteringAreas(meteringAreas);
            params.setExposureCompensation(0);
            YMFLog.error("wudan", "Enable metering area! Metering Area = " + params.getMeteringAreas().toString());
        } else {
            YMFLog.error("wudan", "metering areas not supported");
        }
        mMasterCamera.setParameters(params);
    }

}

private Rect mMeteringRect = null;
public void handleMetering(MotionEvent event, int width, int height) {
    mMeteringRect = calculateTapArea(event.getX(), event.getY(), 1.0f, width, height);
    if (mMeteringRect != null) {
        setMeteringParam();
    }

}

private Rect calculateTapArea(float x, float y, float coefficient, int w, int h) {
    float focusAreaSize = 20;
    int areaSize = Float.valueOf(focusAreaSize * coefficient).intValue();
    int centerX = (int) (x / w * 2000 - 1000);
    int centerY = (int) (y / h * 2000 - 1000);

    int top = clamp(centerX - areaSize / 2, -1000, 1000 - areaSize);
    int left = clamp(centerY - areaSize / 2, -1000, 1000 - areaSize);

    RectF rectF = new RectF(-(left + areaSize),-(top + areaSize), -left, -top);

    return new Rect(Math.round(rectF.left), Math.round(rectF.top), Math.round(rectF.right), Math.round(rectF.bottom));
}

private int clamp(int x, int min, int max) {
    if (x > max) {
        return max;
    }
    if (x < min) {
        return min;
    }
    return x;
}
0

There are 0 answers