Example usage for android.hardware.camera2.params MeteringRectangle MeteringRectangle

List of usage examples for android.hardware.camera2.params MeteringRectangle MeteringRectangle

Introduction

In this page you can find the example usage for android.hardware.camera2.params MeteringRectangle MeteringRectangle.

Prototype

public MeteringRectangle(Rect rect, int meteringWeight) 

Source Link

Document

Create a new metering rectangle.

Usage

From source file:com.dastanapps.camera2.view.Cam2AutoFitTextureView.java

protected void touchToFocus(MotionEvent event) {
    //first stop the existing repeating request
    try {/*from   w  w w  .j  a  va 2 s .c o  m*/
        mPreviewSession.stopRepeating();
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
    Rect rect = mCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
    Log.i(TAG, "SENSOR_INFO_ACTIVE_ARRAY_SIZE,,,,,,,,rect.left--->" + rect.left + ",,,rect.top--->" + rect.top
            + ",,,,rect.right--->" + rect.right + ",,,,rect.bottom---->" + rect.bottom);
    Size size = mCharacteristics.get(CameraCharacteristics.SENSOR_INFO_PIXEL_ARRAY_SIZE);
    Log.i(TAG, "mCameraCharacteristics,,,,size.getWidth()--->" + size.getWidth() + ",,,size.getHeight()--->"
            + size.getHeight());
    int areaSize = 200;
    int right = rect.right;
    int bottom = rect.bottom;
    int viewWidth = getWidth();
    int viewHeight = getHeight();
    int ll, rr;
    Rect newRect;
    int centerX = (int) event.getX();
    int centerY = (int) event.getY();
    ll = ((centerX * right) - areaSize) / viewWidth;
    rr = ((centerY * bottom) - areaSize) / viewHeight;
    int focusLeft = clamp(ll, 0, right);
    int focusBottom = clamp(rr, 0, bottom);
    Log.i(TAG, "focusLeft--->" + focusLeft + ",,,focusTop--->" + focusBottom + ",,,focusRight--->"
            + (focusLeft + areaSize) + ",,,focusBottom--->" + (focusBottom + areaSize));
    newRect = new Rect(focusLeft, focusBottom, focusLeft + areaSize, focusBottom + areaSize);
    MeteringRectangle meteringRectangle = new MeteringRectangle(newRect, 500);
    MeteringRectangle[] meteringRectangleArr = { meteringRectangle };
    mPreviewBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
    mPreviewBuilder.set(CaptureRequest.CONTROL_AF_REGIONS, meteringRectangleArr);
    mPreviewBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO);
    mPreviewBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);
}