Hi, I am using camera2basic example to implement camera2 application. I cannot find a good example for a touch implementation to focus on camera2 api. Currently, the code I use to touch to focus is as follows:
private void setFocusArea(MotionEvent event) { if (mCameraId == null) return; CameraManager cm = (CameraManager)getActivity().getSystemService(Context.CAMERA_SERVICE); CameraCharacteristics cc = null; try { cc = cm.getCameraCharacteristics(mCameraId); } catch (CameraAccessException e) { e.printStackTrace(); } int myX = (int)event.getX(); int myY = (int)event.getY(); MeteringRectangle focusArea = new MeteringRectangle(myX-100,myY-100,200,200,MeteringRectangle.METERING_WEIGHT_DONT_CARE); mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL); try { mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);
But the problem is that it shows strange behavior, while the auto-flash continues to repeat the autofocus sequence for an unlimited time, and this does not seem to focus on the affected area. I tried to change
mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);
in
mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);
this stopped the repeating autofocus sequence, but still does not focus on the affected area, and the flash just blinks for less than a second instead of the usual focus sequence. Please help me with this or advise me to work with a focus example. Thanks
source share