android Camera 如何判断当前使用的摄像头是前置还是后置
来源:互联网 发布:uefi双硬盘安装ubuntu 编辑:程序博客网 时间:2024/05/16 09:03
现在 android 平台的智能手机一般都标配有两颗摄像头。在 Camera 中都存在摄像头切换的功能。
并且有一些功能前后置摄像头上会有所不同。譬如人脸检测,人脸识别,自动对焦,闪光灯等功能,
如果前置摄像头的像素太低,不支持该功能的话,就需要在前置摄像头上关掉该 feature.
那么是如何判断并切换前后置摄像头的呢?
我们先来看下 CameraInfo 这个类,
/** * Information about a camera */ public static class CameraInfo { /** * 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; /** * The direction that the camera faces. It should be * CAMERA_FACING_BACK or CAMERA_FACING_FRONT. */ public int facing; /** * <p>The orientation of the camera image. The value is the angle that the * camera image needs to be rotated clockwise so it shows correctly on * the display in its natural orientation. It should be 0, 90, 180, or 270.</p> * * <p>For example, suppose a device has a naturally tall screen. The * back-facing camera sensor is mounted in landscape. You are looking at * the screen. If the top side of the camera sensor is aligned with the * right edge of the screen in natural orientation, the value should be * 90. If the top side of a front-facing camera sensor is aligned with * the right of the screen, the value should be 270.</p> * * @see #setDisplayOrientation(int) * @see Parameters#setRotation(int) * @see Parameters#setPreviewSize(int, int) * @see Parameters#setPictureSize(int, int) * @see Parameters#setJpegThumbnailSize(int, int) */ public int orientation; };
见名知义,它就是一个 Camera 信息类。它是通过与屏幕的方向是否一致来定义前后置摄像头的。
与屏幕方向相反即为 BACK_FACING_CAMERA
与屏幕方向一致即为 FRONT_FACING_CAMERA
那么在代码中我们是如何获取当前使用的 CamerInfo 呢
Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info);当然,使用该代码的前提是要 import android.hardware.Camera.CameraInfo;
判断使用是前置还是后置摄像头,可以通过if (info.facing == CameraInfo.CAMERA_FACING_FRONT) 来判断。
当Camera 的实例已经创建了的情况下,则需要通过如下方式来判断。
CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId]; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { //stopFaceDetection(); }
也可以通过 if(mCameraId == CameraInfo.CAMERA_FACING_FRONT) 来判断。
其中 mCameraId 是当前使用的 CameraId, 一般前置为1, 后置为 0。- android Camera 如何判断当前使用的摄像头是前置还是后置
- android Camera 如何判断当前使用的摄像头是前置还是后置
- android Camera 如何判断当前使用的摄像头是前置还是后置
- android Camera 如何判断当前使用的摄像头是前置还是后置
- android Camera 如何判断当前使用的摄像头是前置还是后置
- android Camera 如何判断当前使用的摄像头是前置还是后置
- android Camera 如何判断当前使用的摄像头是前置还是后置
- android打开前置摄像头和后置摄像头
- android打开前置摄像头和后置摄像头 .
- android打开前置摄像头和后置摄像头
- 前置摄像头、后置摄像头
- OpenCV Android 打开前置后置摄像头
- IOS获取设备的前置摄像头和后置摄像头
- php如何判断当前的操作系统是linux还是windows
- php如何判断当前的操作系统是linux还是windows
- Android前置后置摄像头录制视频综合版
- JS 判断当前的浏览器是Android 还是IOS
- android 判断手机是否支持前置摄像头
- 多线程
- MeGUI入门教程(2012.12.14更新)
- 黑马程序员-开始
- android多媒体框架之流媒体具体流程篇2----base on jellybean(十二)
- 大牛讲解信号与系统以及数字信号处理
- android Camera 如何判断当前使用的摄像头是前置还是后置
- 黑马程序员_数据库连接Class.forName的作用
- 使用Qt实现简单的图片预览效果
- Spring MVC "The request sent by the client was syntactically incorrect ()"解决办法
- jsp面试基础速成精华讲解
- Zend Framework 入门——错误处理
- java JList 添加数据后,如何更新啊
- Boost.smart_ptr.shared_ptr--2
- Delphi 中的自定义类笔记