Android摄像头Api 2带触摸的手动对焦

Android摄像头Api 2带触摸的手动对焦,android,api,camera,setfocus,Android,Api,Camera,Setfocus,我想让相机应用程序与触摸焦点,但我有点困惑与相机api 2。我读过关于镜头焦距的书,但我不知道如何使用它。你能帮忙吗 提前谢谢你,祝你周末愉快 摄像头API2在begin中看起来很奇怪,但你会发现它非常简单 此问题的最佳答案是带有注释的代码: private void captureImage() { try { //for do this you should have mCameraDevice and mCameraCaptureSession /

我想让相机应用程序与触摸焦点,但我有点困惑与相机api 2。我读过关于镜头焦距的书,但我不知道如何使用它。你能帮忙吗


提前谢谢你,祝你周末愉快

摄像头API2在begin中看起来很奇怪,但你会发现它非常简单

此问题的最佳答案是带有注释的代码:

private void captureImage() {
    try {
        //for do this you should have mCameraDevice and mCameraCaptureSession

        //get CaptureRequestBuilder.
        captureStillBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);

        //add target surfaces - for getting image data you should have instance on ImageReader
        //with OnImageAvailableListener that will be called when image will be captured
        //but for showing on screen you have to use SurfaceView or TextureView
        captureStillBuilder.addTarget(mImageReader.getSurface());

        //add some details for Request
        //in general: you have fields and values for it and you just set what value should be in each field
        // auto focus works only when whole control mode in auto
        captureStillBuilder.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_AUTO);
        // before capture lock focus
        captureStillBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                CaptureRequest.CONTROL_AF_TRIGGER_START);
        // set area for focusing
        MeteringRectangle[] focusArea = new MeteringRectangle[1];            
        focusArea[0] = new MeteringRectangle(/*here set coordinates for focus on */);
        captureStillBuilder.set(CaptureRequest.CONTROL_AF_REGIONS, focusArea);

        // create callback for this capture
        CameraCaptureSession.CaptureCallback callback = new ...
        // just run capture to make focused photo
        mCameraCaptureSession.capture(captureStillBuilder.build(), callback, null);

    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

我不确定。几乎可以肯定——不。当我处理它时,我得到了很多模糊的照片。