我需要计量直播,下面的代码在某些设备(Vivo,oppo)中正常工作,但计量在某些设备(三星和美图)中不起作用,如何计量这些设备?
这是我的代码(触摸屏幕时会调用handleMetering):
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;
}