CameraDevice

public abstract class CameraDevice
extends Object implements AutoCloseable 

The CameraDevice class is a representation of a single camera connected to an Android device, allowing for fine-grain control of image capture and post-processing at high frame rates.

Your application must declare the Camera permission in its manifest in order to access camera devices.

内部类

CameraDevice . StateCallback


A callback objects for receiving updates about the state of a camera device

    private int mCameraId = CameraCharacteristics.LENS_FACING_FRONT;
    private CameraManager mCameraManager; // 相机管理者
    private CameraDevice mCameraDevice; // 相机对象
    private Handler mBackgroundHandler;
    private HandlerThread mBackgroundThread;

    private CameraDevice.StateCallback mStateCallback = new CameraDevice.StateCallback() {
        @Override
        public void onOpened(@NonNull CameraDevice camera) {
            mCameraDevice = camera; // 获取到可用的 CameraDevice 实例
            // 当相机成功打开时回调该方法,接下来可以执行创建预览的操作
        }

        @Override
        public void onDisconnected(@NonNull CameraDevice camera) {
            // 当相机断开连接时回调该方法,应该在此执行释放相机的操作
        }

        @Override
        public void onError(@NonNull CameraDevice camera, int error) {
            // 当相机打开失败时,应该在此执行释放相机的操作
        }

        @Override
        public void onClosed(@NonNull CameraDevice camera) {
            // 当相机关闭时回调该方法,这个方法可以不用实现
        }
    };

    public void openCamera() {
        try {
            // 前处理
            mCameraManager.openCamera(Integer.toString(mCameraId), mStateCallback, mBackgroundHandler);
        } catch (CameraAccessException e) {
            e.printStackTrace();
        }
    }

 Public Methods(常用方法)

  1. void close()

    Close the connection to the camera device as quickly as possible,once the device has fully shut down, the StateCallback#onClosed callback will be called, and the camera is free to be re-opened

  2. CaptureRequest.Builder createCaptureRequest(int templateType)

    Create a CaptureRequest.Builder for new capture requests, initialized with template for a target use case. This methods allows clients to pass physical camera ids which can be used to customize the request for a specific physical camera. 


    Parameters: 


    templateType -- int: An enumeration selecting the use case for this request.                  physicalCameraIdSet -- set :  A set of physical camera ids that can be used to customize the request for a specific physical camera


    Returns:


    CaptureRequest . Builder -- a builder for a capture request, initialized with default settings for that template, and no output streams This value cannot be null.


     

  3. void createCaptureSession(List outputs, CameraCaptureSession.StateCallback, Handler handler)

    使用一个指定的Surface输出列表创建一个相机捕捉回话


    outputs : 输出的 Surface 集合,每个 CaptureRequest 的输出 Surface 都应该是 outputs 的一个子元素。
    callback : 创建会话的回调。成功时将调用 CameraCaptureSession.StateCallback 的 onConfigured(CameraCaptureSession session) 方法。
    handler : 指定回调执行的线程,传 null 时默认使用当前线程的 Looper。
     

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值