Example usage for android.hardware.camera2 CameraCharacteristics SENSOR_INFO_PIXEL_ARRAY_SIZE

List of usage examples for android.hardware.camera2 CameraCharacteristics SENSOR_INFO_PIXEL_ARRAY_SIZE

Introduction

In this page you can find the example usage for android.hardware.camera2 CameraCharacteristics SENSOR_INFO_PIXEL_ARRAY_SIZE.

Prototype

Key SENSOR_INFO_PIXEL_ARRAY_SIZE

To view the source code for android.hardware.camera2 CameraCharacteristics SENSOR_INFO_PIXEL_ARRAY_SIZE.

Click Source Link

Document

Dimensions of the full pixel array, possibly including black calibration pixels.

The pixel count of the full pixel array of the image sensor, which covers CameraCharacteristics#SENSOR_INFO_PHYSICAL_SIZE android.sensor.info.physicalSize area.

Usage

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

protected void touchToFocus(MotionEvent event) {
    //first stop the existing repeating request
    try {/*from   ww  w. j  ava 2s.  co  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);
}