手动对焦于camera2,android

时间:2015-01-27 12:25:10

标签: android camera camera2

我正在寻找android中camera2手动对焦的一个例子。 我试图获得下面显示的最小焦距和可用焦距,但它没有帮助。如何控制焦距?

float minimumLens = characteristics.get(CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE);

float[] lensDistances = characteristics.get(CameraCharacteristics.LENS_INFO_AVAILABLE_FOCAL_LENGTHS); 

我需要用搜索栏来控制它。 提前谢谢。

1 个答案:

答案 0 :(得分:8)

 switch (seekBar.getId()) {
            case R.id.sb_focus:
                float minimumLens = mCameraCharacteristics.get(CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE);
                float num = (((float) i) * minimumLens / 100);
                mPreviewBuilder.set(CaptureRequest.LENS_FOCUS_DISTANCE, num);
                int showNum = (int) num;
                mSeekBarTextView.setText("focus:" + showNum);
                break;}

小心,CONTROL_AF_MODE应为OFF https://github.com/pinguo-yuyidong/Camera2/blob/master/app/src/main/java/us/yydcdut/androidltest/ui/DisplayFragment.java
第1109行的代码