安卓前置摄像头 [英] Android front camera

查看:16
本文介绍了安卓前置摄像头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个函数来检查前置摄像头是否存在,如果存在 - 显示预览.我找到了一些链接,但每个链接都在谈论特定的设备:

I need ONE function to check if front camera exist, and if so - show preview. I found a few links, but each of them talk about a specific device:

谁能为此提供通用代码?或者可能是适用于所有设备的组合代码?

Can anyone provide a generic code for this? Or maybe a combined code that will work with all devices?

推荐答案

对于 API >=9,您可以使用 Camera 类:http://developer.android.com/reference/android/hardware/Camera.html 到查看是否有多个摄像头,并查询 CameraInfo

For APIs >=9, you can use the Camera class: http://developer.android.com/reference/android/hardware/Camera.html to see if it has more than one camera, and query the CameraInfo

  • getNumberOfCameras

getCameraInfo:

http://developer.android.com/reference/android/硬件/Camera.CameraInfo.html

常量

int CAMERA_FACING_BACK 相机的朝向与屏幕的朝向相反.

int CAMERA_FACING_BACK The facing of the camera is opposite to that of the screen.

int CAMERA_FACING_FRONT 摄像头朝向与屏幕朝向一致.

int CAMERA_FACING_FRONT The facing of the camera is the same as that of the screen.


对于 API >=5,一个选项是读取 public List<Camera.Size>getSupportedPictureSizes ().前置摄像头的最大分辨率通常比后置摄像头低得多.


For APIs >=5, an option is to read public List<Camera.Size> getSupportedPictureSizes (). Front facing cameras will usually have much lower max resolution than back cameras.

http://developer.android.com/reference/android/硬件/Camera.Parameters.html

这篇关于安卓前置摄像头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆