Android的前置摄像头摄像头、Android

2023-09-12 01:15:08 作者:慢慢渐渐明了

我需要一个函数来检查前置摄像头的存在,如果是的话 - 显示preVIEW。 我发现了一些联系,但他们每个人谈论的特定设备:

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:

如何打开"前置摄像头" Android平台? http://developer.android.com/reference/android/hardware/Camera.html#open(int Front-facing相机LG擎天柱2X速度 How使用前置摄像头的三星Galaxy S How to open "front camera" on android platform? http://developer.android.com/reference/android/hardware/Camera.html#open(int Front-facing camera on LG Optimus 2X Speed How to use Front Facing Camera on Samsung Galaxy S

任何人都可以提供一个通用的code这个?或者,也许一个组合code,将所有设备的工作?

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

推荐答案

原料药> = 9 ,您可以使用摄像机类: 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/hardware/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.

原料药> = 5 ,一个选择是读公开名单< 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/hardware/Camera.Parameters.html