本文主要是介绍【Android Camera1】Camera1源码分析【Java层】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Camera1源码分析
- 一、摘要
- 二、内部类
- 2.1 Area
- 属性
- 2.2 AutoFocusCallback
- 2.3 AutoFocusMoveCallback
- 2.4 CameraInfo
- 2.4.1 facing
- 2.4.2 orientation
- 2.4.3 canDisableShutterSound
- 2.5 ErrorCallback
- 2.6 EventHandler
- 2.7 Face 和 FaceDetectionListener
- 2.8 IAppOpsCallbackWrapper
- 2.9 OnZoomChangeListener
- 2.10 Parameters
- 2.11 PreviewCallback,PictureCallback,ShutterCallback
- 三、变量
- 三、初始化和销毁
- 3.1 open
- 3.1.1 open()
- 3.1.2 Camera(int cameraId)
- 3.1.3 int cameraInitNormal(int cameraId)
- 3.1.4 int cameraInitNormal(int cameraId)
- 3.2 startPreview
- 3.3 stop and release
- 3.3.1 stopPreview()
- 3.3.1 release()
- 四、参数设置
- 4.1 读取和更新Parameters
- 读取Parameters
- 更新Parameters
- 4.2 参数内容
- 五、拍照
一、摘要
本篇文章介绍Camera1
Java
应用层的源码,只涉及相关API说明以及使用场景,不涉及具体完整功能开发,具体可执行代码可参考Camera1开源项目分析
。感兴趣的也可自行浏览Camera.Java
类。 本篇文章分为如下几个部分讲解:
- 内部类
- 变量
- 初始化和销毁
- 参数设置
- 拍照
二、内部类
内部类 | 用法说明 |
---|---|
Area | 1. 数据结构类:2.3A控制中,标记AF、AE的对焦区域和测光区域 |
AutoFocusCallback | 1. 接口; 2. 自动对焦【单词对焦模式】的回调接口 |
AutoFocusMoveCallback | 1. 接口; 2. 自动对焦【连续对焦模式】的回调接口 |
CameraInfo | 1.类;2. Camera基本信息 |
ErrorCallback | Camera发生错误回调接口 |
EventHandler | Camera事件分发线程Handle |
Face | 人脸信息数据结构类 |
FaceDetectionListener | 人脸检测Listener |
IAppOpsCallbackWrapper | Audio状态变更回调 |
OnZoomChangeListener | Zoom缩放Change回调 |
Parameters | Camera 参数管理类 |
PictureCallback | 拍照回调 |
PreviewCallback | 预览回调 |
ShutterCallback | 拍照咔擦声音回调 |
Size | Image Size数据结构类 |
2.1 Area
Area
主要涉及到对相机的3A控制自动对焦
,自动曝光
,自动白平衡
流程。更详细的细节会在Camera1系列3A相关文章中进行阐述,这里只做简要介绍。3A算法的理论介绍可参看:Camera理论知识和基本原理
具体体现在代码实现层面,在Camera1中体现的数据结构类是Area
。它承载了相机预览界面的区域以及该区域的权重。
- 自动对焦可根据对应区域进行对焦保证对应区域的画面清晰
- 自动曝光可根据对应区域进行测光来保证对应区域的曝光亮度是正常的
属性
- rect :界定区域边界,范围为 [-1000,1000],是Camera1内部相机的坐标系
The bounds are relative to the camera’s current field of view. The coordinates are mapped so that (-1000, -1000) is top-left corner and (1000, 1000) is bottom-right corner. Bounds outside is not allowed. zero or negative width or height are not allowed.
- weight : 该区域的权重,[1,1000] 在实际应用中基本都直接设为1000
The weight represents a weight for every pixel in the area. This means that a large metering area with the same weight as a smaller area will have more effect in the metering result. Metering areas can overlap and the driver will add the weights in the overlap region.
2.2 AutoFocusCallback
调用 mCamera.autoFocus(AutoFocusCallback)传入
void onAutoFocus(boolean success, Camera camera)
- success表示自动对焦成功还是失败,可根据此字段来1.重试对焦;2.刷新UI;3.提示用户;4.统计等
说明:
autoFocus
对焦仅限在FocusModo
为"auto-focus"
的情况下使用,如果相机不支持该模式,则实际上是假生效。具体对焦模式可参考文章后方相关API
2.3 AutoFocusMoveCallback
void onAutoFocusMoving(boolean start, Camera camera);
- 标志对焦的开始和结束
- 在对焦模式为:
FOCUS_MODE_CONTINUOUS_VIDEO
和FOCUS_MODE_CONTINUOUS_PICTURE
时生效
2.4 CameraInfo
这是一个很重要的类,而且实际开发过程中的坑也很多,该类包含如下几个属性
2.4.1 facing
一半手机设备会存在前置摄像头和后置摄像头2个。具体描述可参考Android Camera理论协议和规范里关于相机相关的协议。不同的App打开,会默认开启前置或者后置摄像头。
前置后置摄像头根据cameraId
进行区分,一般情况下cameraId = 0
为后置,cameraId = 1
为前置。Camera1
、Camera2
、CameraX
关于摄像头方向的描述上有一定的概念差异,一定要进行区分。
CameraInfo
类里有如下2个静态常量
/**
* The facing of the camera is opposite to that of the screen.
*/
public static final int CAMERA_FACING_BACK = 0;
/**
* The facing of the camera is the same as that of the screen.
*/
public static final int CAMERA_FACING_FRONT = 1;
注意这2个常量的注释。The facing of the camera is opposite to that of the screen
跟屏幕相反的方向以及The facing of the camera is the same as that of the screen.
跟屏幕相同的方向。这里是用跟屏幕的相同相反来进行区分,并不是明确的标志0->后置。 因为在折叠屏幕上,屏幕可折叠,正反面都是屏幕,这时或许需要单独考虑下差异性。
2.4.2 orientation
这也是经常会有坑的地方,众所周知大部分手机都是竖着的,即height > width
【不考虑折叠屏,PAD,分屏等情况】,通常相机后置frame流和手机方向会有90度的夹角,前置frame流和手机方向有270度的夹角。所以一般后置我们都要手动设置90。如:mCamera.setDisplayOrientation(90)
。更直观的如下:
可以看到90度为正常的方向。
当然在实际的计算中,考虑到手机方向也会随着传感器变化,通常会计算最终的targetOrientation值,这里贴上官方Demo的计算函数:
/*** Calculate display orientation
https://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation(int)*/private int calcDisplayOrientation() {CameraInfo info = new Camera.CameraInfo();android.hardware.Camera.getCameraInfo(cameraId, info);int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();int degrees = 0;switch (rotation) {case Surface.ROTATION_0: degrees = 0; break;case Surface.ROTATION_90: degrees = 90; break;case Surface.ROTATION_180: degrees = 180; break;case Surface.ROTATION_270: degrees = 270; break;}int result;if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {result = (info.orientation + degrees) % 360;result = (360 - result) % 360; // compensate the mirror} else { // back-facingresult = (info.orientation - degrees + 360) % 360;}camera.setDisplayOrientation(result);}
!!虽说大部分都遵循如上规则,但Android手机厂商,型号碎片化过多,有一些手机不遵循后置Frame和手机90度夹角的规则,如Nexus 6等手机,这种情况下就需要单独去做兼容处理
2.4.3 canDisableShutterSound
这个特性也是Camera1中特有的,也是经常会遇到坑的地方。在Camera1
中拍照会有声音提示,该属性表示是否可以关闭声音提示。因此就会有如下坑:
- 某些手机不能关闭声音提示如一些小米机型,就需要花费额外较大的成本去兼容这些机型
- 通过
Camera.getCameraInfo(cameraId, info);
去获取相关字段值的时候,canDisableShutterSound
和手机的Audio
系统有关系。在某些手机上会抛异常,如果没有注意到这个异常将会导致相机功能不可用。因此对该字段的处理要更细致一些。具体我将在Camera1初始化文章中进行阐述
2.5 ErrorCallback
主要用来捕获相机执行过程中发生的一些错误情况,抛出具体的errorCode
给开发人员
void onError(int error, Camera camera);
。在实际开发一个健壮性比较高的Camera1能力应用App中,你将会在不同的Android机型发现各种奇奇怪怪的错误。
2.6 EventHandler
Handle类,所在的线程和初始化相机的业务线程保持一致。
2.7 Face 和 FaceDetectionListener
检测人脸相关类,通常在前置摄像头场景下开启,但会影响性能,实际应用场景不多。Face则是一个代表人脸信息的数据结构类,提供非常简单的人脸信息:
public Rect rect;
[-1000,1000]public int id = -1;
public Point leftEye = null;
Point rightEye = null;
public Point mouth = null;
public int score;
2.8 IAppOpsCallbackWrapper
该接口主要和canDisableShutterSound
有关,实际会监听手机状态,动态更改canDisableShutterSound
。实际应用场景很少,感兴趣的可参考,该类下的:private void updateAppOpsPlayAudio()
方法。
2.9 OnZoomChangeListener
Zoom值改变的时候通过回掉告诉上层当前缩放系数为多少,实际开发中很少用到 有如下接口:
void onZoomChange(int zoomValue, boolean stopped, Camera camera);
2.10 Parameters
在四、参数设置模块
进行详细阐述
2.11 PreviewCallback,PictureCallback,ShutterCallback
分辨对应相机开始预览时候的回掉,拍照时候的毁掉,和ShutterCallback用来提示用户快门声音,对应如下接口:
void onPreviewFrame(byte[] data, Camera camera);
void onPictureTaken(byte[] data, Camera camera);
void onShutter();
三、变量
变量名 | 说明 |
---|---|
CAMERA_MSG_ERROR | Msg Code:Camera错误消息 |
CAMERA_MSG_SHUTTER | Msg Code:Camera快门消息 |
CAMERA_MSG_FOCUS | Msg Code:Camera对焦消息 |
CAMERA_MSG_ZOOM | Msg Code:Camera缩放消息 |
CAMERA_MSG_PREVIEW_FRAME | Msg Code:Camera预览帧消息 |
CAMERA_MSG_VIDEO_FRAME | Msg Code:Camera视频帧消息 |
CAMERA_MSG_POSTVIEW_FRAME | Msg Code:Camera onPictureTaken消息 |
CAMERA_MSG_RAW_IMAGE | Msg Code:Camera 拍照raw数据流消息 |
CAMERA_MSG_COMPRESSED_IMAGE | Msg Code:Camera 拍照过程中compressed消息 |
CAMERA_MSG_RAW_IMAGE_NOTIFY | Msg Code:Camera 拍照过程中完成拍照返Raw数据消息 |
CAMERA_MSG_PREVIEW_METADATA | Msg Code:onFaceDetection消息 |
CAMERA_MSG_FOCUS_MOVE | Msg Code:onAutoFocusMoving消息 |
mNativeContext | 上下文 |
mEventHandler | / |
mShutterCallback、mRawImageCallback、mJpegCallback、mPreviewCallback、mPostviewCallback | 预览拍照的回调接口 |
mAutoFocusCallback、mAutoFocusMoveCallback、mZoomListener、mFaceListener | 自动对焦,移动对焦,缩放,人脸检测回调 |
mErrorCallback、mDetailedErrorCallback | 错误处理回调 |
ACTION_NEW_PICTURE | Broadcast Action: A new picture is taken by the camera, and the entry of the picture has been added to the media store. |
ACTION_NEW_VIDEO | Broadcast Action: A new video is recorded by the camera, and the entry of the video has been added to the media store. |
CAMERA_FACE_DETECTION_HW | Hardware face detection. It does not use much CPU |
CAMERA_FACE_DETECTION_SW | Software face detection. It uses some CPU. |
三、初始化和销毁
本节只介绍和初始化销毁相关的源码API。具体完善的初始化销毁代码可参考Camera1初始化销毁文章和Camera1源码项目分析文章。和初始化销毁相关的核心函数如下:
函数 |
---|
1.Camera(int cameraId) |
2.cameraInitNormal(int cameraId) |
3.cameraInitVersion(int cameraId, int halVersion) |
4.native final int native_setup(Object camera_this, int cameraId, int halVersion, String packageName) |
5.Camera open() |
6.Camera open(int cameraId) |
7.native final void startPreview(); |
8.void stopPreview() |
9.native final void _stopPreview() |
10. void release() |
11. native final void native_release(); |
12. void releaseAppOps() |
以上函数可归纳为如下4个模块,每个模块最后的函数调用都指向native函数。
模块 |
---|
open |
startPreview |
stopPreview |
release |
3.1 open
执行顺序为 5 -> 6 -> 1 -> 2 -> 3 -> 4
3.1.1 open()
public static Camera open() {int numberOfCameras = getNumberOfCameras();CameraInfo cameraInfo = new CameraInfo();for (int i = 0; i < numberOfCameras; i++) {getCameraInfo(i, cameraInfo);if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {return new Camera(i);}}return null;}
native static int getNumberOfCameras();
native获取手机相机的数目。getCameraInfo(i, cameraInfo);
获取对应cameraId的cameraInfo->【 2.4.1】
- 默认初始化后置
CameraInfo.CAMERA_FACING_BACK
3.1.2 Camera(int cameraId)
Camera(int cameraId) {int err = cameraInitNormal(cameraId);if (checkInitErrors(err)) {if (err == -EACCES) {throw new RuntimeException("Fail to connect to camera service");} else if (err == -ENODEV) {throw new RuntimeException("Camera initialization failed");}// Should never hit this.throw new RuntimeException("Unknown camera error");}initAppOps();}
- cameraInitNormal(cameraId);
->【3.1.3】
- 处理异常错误,注意这里只单独识别了
-EACCES
和-ENODEV
错误信息 initAppOps();
处理canDisableShutterSound
实际场景接触几乎没有,其他可参考-> 2.4.3,2.8
3.1.3 int cameraInitNormal(int cameraId)
private int cameraInitNormal(int cameraId) {return cameraInitVersion(cameraId, CAMERA_HAL_API_VERSION_NORMAL_CONNECT);}
CAMERA_HAL_API_VERSION_NORMAL_CONNECT
为HAL的版本号有如下3个版本号,了解即可,开发场景不会遇到。
/*** Camera HAL device API version 1.0* @hide*/@UnsupportedAppUsagepublic static final int CAMERA_HAL_API_VERSION_1_0 = 0x100;/*** A constant meaning the normal camera connect/open will be used.*/private static final int CAMERA_HAL_API_VERSION_NORMAL_CONNECT = -2;/*** Used to indicate HAL version un-specified.*/private static final int CAMERA_HAL_API_VERSION_UNSPECIFIED = -1;
3.1.4 int cameraInitNormal(int cameraId)
private int cameraInitVersion(int cameraId, int halVersion) {mShutterCallback = null;mRawImageCallback = null;mJpegCallback = null;mPreviewCallback = null;mPostviewCallback = null;mUsingPreviewAllocation = false;mZoomListener = null;Looper looper;if ((looper = Looper.myLooper()) != null) {mEventHandler = new EventHandler(this, looper);} else if ((looper = Looper.getMainLooper()) != null) {mEventHandler = new EventHandler(this, looper);} else {mEventHandler = null;}return native_setup(new WeakReference<Camera>(this), cameraId, halVersion,ActivityThread.currentOpPackageName());}
- 重置变量 ->
【三】
- 初始化
mEventHandle
这里要注意,camera1流程消息队列和使用Camera相机能力业务保持一致 native_setup
native 函数调用。其参数是Camera.java
实例类,cameraId
,hal版本号
,packageName
3.2 startPreview
1. capture,drawing preview frames
2. 需要surface
*************/*** Starts capturing and drawing preview frames to the screen.* Preview will not actually start until a surface is supplied* with {@link #setPreviewDisplay(SurfaceHolder)} or* {@link #setPreviewTexture(SurfaceTexture)}.**/
相关函数常用的如1
1.setPreviewCallback(Camera.PreviewCallback)
*************/** <p>If {@link #setPreviewCallback(Camera.PreviewCallback)},* {@link #setOneShotPreviewCallback(Camera.PreviewCallback)}, or* {@link #setPreviewCallbackWithBuffer(Camera.PreviewCallback)} were* called, {@link Camera.PreviewCallback#onPreviewFrame(byte[], Camera)}* will be called when preview data becomes available.
**/
异常处理
1. 硬件错误
2. 设备兼容性错误
3. startPreview时发现camera is release
4. connect fail
5. previewSize设置不对
6. pictureSize设置不对
7. 其他
以上的没一种错误都会影响用户的实际体验,因此好的应用就需要用各种方式解决如上错误。详细可参考Camera1初始化文章
*************/** @throws RuntimeException if starting preview fails; usually this would be* because of a hardware or other low-level error, or because release()* has been called on this Camera instance. The QCIF (176x144) exception* mentioned in {@link Parameters#setPreviewSize setPreviewSize} and* {@link Parameters#setPictureSize setPictureSize} can also cause this* exception be thrown.*/public native final void startPreview();
3.3 stop and release
stop
和release
流程经常放在一起,常见的场景如下:
- 切前后台
- 切前后置
- 切画幅
- 切拍照和视频模式
- 切页面
执行顺序:8 -> 9 -> 10 -> 11
3.3.1 stopPreview()
同样需要特别注意异常捕获和处理
**************/*** Stops capturing and drawing preview frames to the surface, and* resets the camera for a future call to {@link #startPreview()}.** @throws RuntimeException if stopping preview fails; usually this would be* because of a hardware or other low-level error, or because release()* has been called on this Camera instance.*/public final void stopPreview() {_stopPreview();mFaceDetectionRunning = false;mShutterCallback = null;mRawImageCallback = null;mPostviewCallback = null;mJpegCallback = null;synchronized (mAutoFocusCallbackLock) {mAutoFocusCallback = null;}mAutoFocusMoveCallback = null;}private native final void _stopPreview();
3.3.1 release()
断开和camera
的链接以及释放资源
/*** Disconnects and releases the Camera object resources.** <p>You must call this as soon as you're done with the Camera object.</p>*/public final void release() {native_release();mFaceDetectionRunning = false;releaseAppOps();}private native final void native_release();
四、参数设置
对Camera1
所有的参数设置都将通过Parameters
4.1 读取和更新Parameters
主要涉及到2个函数。
public Parameters getParameters()
public void setParameters(Parameters params)
/*** Returns the current settings for this Camera service.* @throws RuntimeException if reading parameters fails; usually this would* be because of a hardware or other low-level error, or because* release() has been called on this Camera instance.* @see #setParameters(Camera.Parameters)*/public Parameters getParameters() {Parameters p = new Parameters();String s = native_getParameters();p.unflatten(s);return p;}/*** Changes the settings for this Camera service.** @param params the Parameters to use for this Camera service* @throws RuntimeException if any parameter is invalid or not supported.* @see #getParameters()*/public void setParameters(Parameters params) {// If using preview allocations, don't allow preview size changesif (mUsingPreviewAllocation) {Size newPreviewSize = params.getPreviewSize();Size currentPreviewSize = getParameters().getPreviewSize();if (newPreviewSize.width != currentPreviewSize.width ||newPreviewSize.height != currentPreviewSize.height) {throw new IllegalStateException("Cannot change preview size" +" while a preview allocation is configured.");}}native_setParameters(params.flatten());}
代码如上,这里尤其要注意以下问题:
- 参数读取和设置不影响相机功能
- 但是参数读取和设置都会抛异常
在实际开发使用一定要单独包装2个函数:
读取Parameters
public static @Nullable Camera.Parameters getCameraParameters(@NonNull Camera camera) {try {return camera.getParameters();}catch (Exception e){return null;}}
getCameraParameters
要保证传入的camera
实例不为null
;getCameraParameters
会返回null
需要对返回值做处理
更新Parameters
public static boolean setCameraParameters(@NonNull Camera camera, @NonNull Camera.Parameters parameters) {try {camera.setParameters(parameters);return true;}catch (Exception e){return false;}}
同样需要保证传入参数的正确性,以及对返回值进行处理。
4.2 参数内容
本节只是简要说明具体的参数项,不会特殊去阐述每个设置的效果,如需了解,请参看Camera1系列文章之参数设置
一文。Parameters
里有一个Map
存放对应的Key
->Value
。该类的方法函数也是获取对应Key的Value值,感兴趣的可自行浏览源码,这里就不重复阐述了。
以下以红米note9为机型获取到的具体参数值,意识可按照属性value字面意思理解即可。实际的效用,可参看Camera1系列文章之参数设置。
Key变量名 | Key变量值 | Value值 | 说明 |
---|---|---|---|
KEY_PREVIEW_SIZE | preview-size | 1440x1080 | 预览尺寸;【1440x1080 1920x1080,1600x960…】 |
KEY_PREVIEW_FORMAT | preview-format | yuv420sp | 预览格式;【yuv420p,yuv420sp,yuv420p】 |
KEY_PREVIEW_FRAME_RATE | preview-frame-rate | 30 | 当前预览帧率【10,15,20,30】 |
KEY_PREVIEW_FPS_RANGE | preview-fps-range | 5000,30000 | 5,30 |
KEY_PICTURE_SIZE | picture-size | 3264x2448 | 照片尺寸:【4000x2992,4000x2240,4000x1808… 】 |
KEY_PICTURE_FORMAT | picture-format | jpeg | 范围:【jpeg】 |
KEY_JPEG_THUMBNAIL_SIZE | jpeg-thumbnail-size | 250,187 | 范围:【0x0,160x96,162x121,192x108…】 |
KEY_JPEG_THUMBNAIL_WIDTH | jpeg-thumbnail-width | 250 | / |
KEY_JPEG_THUMBNAIL_HEIGHT | jpeg-thumbnail-height | 187 | / |
KEY_JPEG_THUMBNAIL_QUALITY | jpeg-thumbnail-quality | 90 | 缩略图质量 |
KEY_JPEG_QUALITY | jpeg-quality | 90 | takePic图片质量 |
KEY_ROTATION | rotation | 90 | / |
KEY_GPS_LATITUDE | gps-latitude | / | gps信息 |
KEY_GPS_LONGITUDE | gps-longitude | / | gps信息 |
KEY_GPS_ALTITUDE | gps-altitude | / | gps信息 |
KEY_GPS_TIMESTAMP | gps-timestamp | / | gps信息 |
KEY_GPS_PROCESSING_METHOD | gps-processing-method | / | / |
KEY_WHITE_BALANCE | whitebalance | auto | 【auto,incandescent,fluorescent,warm-fluorescent,daylight,cloudy-daylight,twilight,shade】 |
KEY_EFFECT | effect | none | 【none】 |
KEY_ANTIBANDING | antibanding | auto | 【off,50hz,60hz,auto】 |
KEY_SCENE_MODE | scene-mode | auto | 【auto,action,portrait,landscape,night,night-portrait,theatre,beach,snow,sunset,steadyphoto,fireworks,sports,party,candlelight,barcode,hdr】 |
KEY_FLASH_MODE | flash-mode | auto | 【off,auto,on,torc】和刷新率有关系,例如刷新率不对会出现摩尔纹等问题 |
KEY_FOCUS_MODE | focus-mode | continuous-picture | 【auto,macro,continuous-video,continuous-picture】 |
KEY_FOCUS_AREAS | focus-areas | (0,0,0,0,0) | 对焦区域 |
KEY_MAX_NUM_FOCUS_AREAS | max-num-focus-areas | 1 | 支持最大的对焦区域个数 |
KEY_FOCAL_LENGTH | focal-length | 4.695 | |
KEY_HORIZONTAL_VIEW_ANGLE | horizontal-view-angle | 68.5548 | |
KEY_VERTICAL_VIEW_ANGLE | vertical-view-angle | 54.1506 | |
KEY_EXPOSURE_COMPENSATION | exposure-compensation | 0 | |
KEY_MAX_EXPOSURE_COMPENSATION | max-exposure-compensation | 24 | |
KEY_MIN_EXPOSURE_COMPENSATION | min-exposure-compensation | -24 | |
KEY_EXPOSURE_COMPENSATION_STEP | exposure-compensation-step | 0.166667 | 实际曝光值需要step*exposure-compensation值 |
KEY_AUTO_EXPOSURE_LOCK | auto-exposure-lock | false | |
KEY_AUTO_EXPOSURE_LOCK_SUPPORTED | auto-exposure-lock-supported | true | |
KEY_AUTO_WHITEBALANCE_LOCK | auto-whitebalance-lock | false | |
KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED | auto-whitebalance-lock-supported | true | |
KEY_METERING_AREAS | metering-areas | (0,0,0,0,0) | |
KEY_MAX_NUM_METERING_AREAS | max-num-metering-areas | 1 | |
KEY_ZOOM | zoom | 0 | |
KEY_MAX_ZOOM | max-zoom | 99 | 1 - 99 99个刻度映射到实际摄像头的zoom |
KEY_ZOOM_RATIOS | zoom-ratios | 100~999 | 对应1f - 9.99f |
KEY_ZOOM_SUPPORTED | zoom-supported | true | |
KEY_SMOOTH_ZOOM_SUPPORTED | smooth-zoom-supported | false | |
KEY_FOCUS_DISTANCES | focus-distances | Infinity,Infinity,Infinity | |
KEY_VIDEO_SIZE | video-size | 1920x1080 | 3840x2160,2400x1080,2340x1080… |
KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO | preferred-preview-size-for-video | 1920x1080 | |
KEY_MAX_NUM_DETECTED_FACES_HW | max-num-detected-faces-hw | 15 | |
KEY_MAX_NUM_DETECTED_FACES_SW | max-num-detected-faces-sw | 0 | |
KEY_RECORDING_HINT | recording-hint | false | 录制提示 |
KEY_VIDEO_SNAPSHOT_SUPPORTED | video-snapshot-supported | false | |
KEY_VIDEO_STABILIZATION | video-stabilization | false | true 也实际没啥用 |
KEY_VIDEO_STABILIZATION_SUPPORTED | video-stabilization-supported | true |
五、拍照
源码API提供的函数基本上就是直接调用native函数,传入回调函数。实际的用法其实比较复杂,具体细节可参看Camera1系列文章之拍照
/*** Equivalent to <pre>takePicture(Shutter, raw, null, jpeg)</pre>.** @see #takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)*/public final void takePicture(ShutterCallback shutter, PictureCallback raw,PictureCallback jpeg) {takePicture(shutter, raw, null, jpeg);}private native final void native_takePicture(int msgType);
这篇关于【Android Camera1】Camera1源码分析【Java层】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!