相机setRepeatingRequest问题,它只工作一次,之后无效

时间:2015-10-25 20:55:29

标签: android camera touch focus ontouch

我有一个相机应用程序,我专注于触摸,但问题是,在我设置AF和AE区域后,我触发焦点后,我设置了setRepeatingRequest(),所以我可以看到预览,但它仅在我第一次触摸屏幕时工作,之后没有任何变化(没有焦点或闪光灯正在触摸),请帮忙,我不知道出了什么问题!

这是我的代码:

    private void autofoc() {
    mTextureView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN:

                Rect rect = cameraCharacteristics
                        .get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
                Size size = cameraCharacteristics
                        .get(CameraCharacteristics.SENSOR_INFO_PIXEL_ARRAY_SIZE);
                int areaSize = 200;
                int right = rect.right;
                int bottom = rect.bottom;
                int viewWidth = mTextureView.getWidth();
                int viewHeight = mTextureView.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);

                newRect = new Rect(focusLeft, focusBottom, focusLeft
                        + areaSize, focusBottom + areaSize);
                MeteringRectangle meteringRectangle = new MeteringRectangle(
                        newRect, 500);
                MeteringRectangle[] meteringRectangleArr = { meteringRectangle };

                System.out.println("metering rectARR"
                        + meteringRectangleArr);

                mPreviewCaptureRequestBuilder.set(CaptureRequest.CONTROL_MODE,
                        CameraMetadata.CONTROL_MODE_AUTO);

                mPreviewCaptureRequestBuilder.set(
                        CaptureRequest.CONTROL_AF_REGIONS,
                        meteringRectangleArr);

                mPreviewCaptureRequestBuilder.set(
                        CaptureRequest.CONTROL_AE_REGIONS,
                        meteringRectangleArr);

                mPreviewCaptureRequestBuilder.set(
                        CaptureRequest.CONTROL_AF_TRIGGER,
                        CameraMetadata.CONTROL_AF_TRIGGER_START);

                mPreviewCaptureRequestBuilder.set(
                        CaptureRequest.CONTROL_AF_MODE,
                        CameraMetadata.CONTROL_AF_MODE_AUTO);




                if(flash_value == 1){
                    mPreviewCaptureRequestBuilder.set(
                            CaptureRequest.CONTROL_AE_MODE,
                            CameraMetadata.CONTROL_AE_MODE_ON_ALWAYS_FLASH);
                    mPreviewCaptureRequestBuilder.set(
                            CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
                            CameraMetadata.CONTROL_AE_PRECAPTURE_TRIGGER_START);
                }


                try {
                    mCameraCaptureSession.setRepeatingRequest(
                        mPreviewCaptureRequestBuilder.build(),
                        mSessionCaptureCallback, mBackgroundHandler);

                } catch (CameraAccessException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                break;
            }

            return true;

        }
    });

1 个答案:

答案 0 :(得分:0)

您只能使用mCameraCaptureSession.capture致电CONTROL_AF_TRIGGER_START一次。

请参阅我的回答here