一步一步解析google camera2 demo(一)

版权声明:本文为博主原创文章,转载请注明出处 http://blog.csdn.net/u013961718 https://blog.csdn.net/u013961718/article/details/87869304

目录:
一、Camera2关键类解析
二、打开相机
三、预览
四、拍照

一、Camera2关键类解析

1、CameraManager

A system service manager for detecting, characterizing, and connecting to CameraDevices.

  • public String[] getCameraIdList ()

     函数功能:返回所有可用相机设备的id列表。
    
  • public CameraCharacteristics getCameraCharacteristics (String cameraId)

     函数功能:查询指定相机设备的特性,对于指定的相机设备,这些特性是不变的。
    
  • public void openCamera (String cameraId, CameraDevice.StateCallback callback, Handler handler)

     函数功能:打开指定摄像头。
       cameraId:代表要打开的摄像头Id。
       callback:camera open完之后响应的回调。
       handler:执行callback的Handler,如果程序希望直接在当前线程中执行callback,则handler设置为null。
    

2、CameraCharacteristics

The properties describing a CameraDevice.

  • LENS_FACING

     相机相对屏幕设备的方向。(FRONT、BACK、EXTERNAL)
    
  • SCALER_STREAM_CONFIGURATION_MAP

     相机设备支持的stream配置信息。
    
  • SENSOR_ORIENTATION

     顺时针角度,输出图像需要通过该角度以原始方向旋转到设备屏幕上。(0, 90, 180, 270)
    
  • FLASH_INFO_AVAILABLE

     相机设备是闪光灯是否可用
    

3、CameraDevice

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.

  • public abstract CaptureRequest.Builder createCaptureRequest (int templateType)

     函数功能:根据template类型为目标use case创建CaptureRequest.Builder。
       TEMPLATE_PREVIEW:      预览
       TEMPLATE_STILL_CAPTURE:拍照
       TEMPLATE_RECORD:       录像
    
  • public abstract void createCaptureSession (List outputs, CameraCaptureSession.StateCallback callback, Handler handler)

     函数功能:根据提供给相机设备的target output Surface集合创建camera capture session。
       outputs:用于创建session的surface集合。
       callback:session创建完成后响应的回调。
       handler:执行callback的Handler,如果程序希望直接在当前线程中执行callback,则handler设置为null。
    

4、CaptureRequest.Builder

A builder for capture requests.

  • public void addTarget (Surface outputTarget)

     函数功能:给要生成的request添加surface。添加的surface一定要属于创建session时指定的surface list。
    
  • public void set (Key key, T value)

     函数功能:给要生成的request设置settings。
       Key: The metadata field to write.
       T: The value to set the field to, which must be of a matching type to the key.
     
     // 案例,设置自动曝光
     captureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE,CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
    
  • public CaptureRequest build ()

     函数功能:生成request根据已设置的target surface和settings。
    

5、CameraCaptureSession

A configured capture session for a CameraDevice, used for capturing images from the camera or reprocessing images captured from the camera in the same session previously.
The active capture session determines the set of potential output Surfaces for the camera device for each capture request. A given request may use all or only some of the outputs. Once the CameraCaptureSession is created, requests can be submitted with capture, captureBurst, setRepeatingRequest, or setRepeatingBurst.

  • public abstract int setRepeatingRequest (CaptureRequest request, CameraCaptureSession.CaptureCallback listener, Handler handler)

     函数功能:启预览,以最快的速度重复submit request。再次调用该函数会清除掉之前设置的request,而使用新的request。
       request:用于重复submit的request。
       listener:每个request处理完成后都会响应这个listener,可以为null。
       handler:执行callback的Handler,如果程序希望直接在当前线程中执行callback,则handler设置为null。
    
  • public abstract void stopRepeating ()

     函数功能:用于取消之前设置的repeating request。
     当前正在处理的request依然会处理完成,待所有request处理完成后,会响应CameraCaptureSession.StateCallback.onReady(CameraCaptureSession)。
    
  • public abstract void abortCaptures ()

     函数功能:尽可能快地丢掉等待状态和正在处理的request。会触发native camera的flush。
    
  • public abstract int capture (CaptureRequest request, CameraCaptureSession.CaptureCallback listener, Handler handler)

     函数功能:拍照,request处理完成后在listener响应。拍照的request比预览的request,会被指定的request pending队列的队头。
    

6、CaptureRequest

An immutable package of settings and outputs needed to capture a single image from the camera device.
Contains the configuration for the capture hardware (sensor, lens, flash), the processing pipeline, the control algorithms, and the output buffers. Also contains the list of target Surfaces to send image data to for this capture.

7、CameraCaptureSession.CaptureCallback

A callback object for tracking the progress of a CaptureRequest submitted to the camera device.
This callback is invoked when a request triggers a capture to start, and when the capture is complete. In case on an error capturing an image, the error method is triggered instead of the completion method.

  • public void onCaptureCompleted (CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result)

     函数功能:capture完成并且所有的result metadata都返回触发。
    
  • public void onCaptureProgressed (CameraCaptureSession session, CaptureRequest request, CaptureResult partialResult)

     函数功能:partial metadata返回时调用,partial metadata是full metadata的子集,为了提高性能,有一些metadata数据应用需要提前获取到。
    

猜你喜欢

转载自blog.csdn.net/u013961718/article/details/87869304
今日推荐