Android Camera Api 2 触摸手动对焦

标签 android api camera setfocus

我想制作带有触摸对焦的相机应用程序,但我对相机 API 2 有点困惑。我已经阅读了有关 LENS_FOCUS_DISTANCE 的内容,但我不明白如何使用它。你能帮忙吗?

在此先感谢您,祝您周末愉快!

最佳答案

Camera API2 开始时看起来很奇怪,但随后您会发现它非常简单。

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

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();
    }
}

关于Android Camera Api 2 触摸手动对焦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29708146/

相关文章:

android - facebook 处理共享 Intent 的方法 - 如何处理它

python-3.x - 从盈透证券的 API 获取多个最后报价

python - 集成pylint和github评论评论

ios - UIImagePicker 源类型不想改变

iphone - 更改 ISO 或快门速度

c++ - 如何在Qt 5.3中使用QCamera设置图像分辨率?

java - 自定义 ListAdapter 不显示所有字段

android - 代理后未收到 Firebase 通知

android - 如果我从我的 Android 应用程序中排除所有 64 位库,它是否会完全以 32 位模式运行?

android - 有没有办法可以在 android honeycomb 的主线程上调用网络 API 调用?