本文整理了Java中android.hardware.Camera.getNumberOfCameras()
方法的一些代码示例,展示了Camera.getNumberOfCameras()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Camera.getNumberOfCameras()
方法的具体详情如下:
包路径:android.hardware.Camera
类名称:Camera
方法名:getNumberOfCameras
暂无
代码示例来源:origin: LaiFeng-Android/SopCastComponent
public int getNumberOfCameras() {
return Camera.getNumberOfCameras();
}
代码示例来源:origin: ankidroid/Anki-Android
@Override
@SuppressWarnings("deprecation")
public int getCameraCount() { return android.hardware.Camera.getNumberOfCameras(); }
代码示例来源:origin: vondear/RxTool
/**
* This rewrites {@link #mCameraId} and {@link #mCameraInfo}.
*/
private void chooseCamera() {
for (int i = 0, count = Camera.getNumberOfCameras(); i < count; i++) {
Camera.getCameraInfo(i, mCameraInfo);
if (mCameraInfo.facing == mFacing) {
mCameraId = i;
return;
}
}
mCameraId = INVALID_CAMERA_ID;
}
代码示例来源:origin: google/cameraview
/**
* This rewrites {@link #mCameraId} and {@link #mCameraInfo}.
*/
private void chooseCamera() {
for (int i = 0, count = Camera.getNumberOfCameras(); i < count; i++) {
Camera.getCameraInfo(i, mCameraInfo);
if (mCameraInfo.facing == mFacing) {
mCameraId = i;
return;
}
}
mCameraId = INVALID_CAMERA_ID;
}
代码示例来源:origin: daniulive/SmarterStreaming
private int findBackCamera() {
int cameraCount = 0;
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
cameraCount = Camera.getNumberOfCameras();
for (int camIdx = 0; camIdx < cameraCount; camIdx++) {
Camera.getCameraInfo(camIdx, cameraInfo);
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
return camIdx;
}
}
return -1;
}
代码示例来源:origin: daniulive/SmarterStreaming
private int findBackCamera(){
int cameraCount = 0;
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
cameraCount = Camera.getNumberOfCameras();
for ( int camIdx = 0; camIdx < cameraCount;camIdx++ ) {
Camera.getCameraInfo( camIdx, cameraInfo );
if ( cameraInfo.facing ==Camera.CameraInfo.CAMERA_FACING_BACK ) {
return camIdx;
}
}
return -1;
}
代码示例来源:origin: daniulive/SmarterStreaming
private int findFrontCamera() {
int cameraCount = 0;
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
cameraCount = Camera.getNumberOfCameras();
for (int camIdx = 0; camIdx < cameraCount; camIdx++) {
Camera.getCameraInfo(camIdx, cameraInfo);
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
return camIdx;
}
}
return -1;
}
代码示例来源:origin: daniulive/SmarterStreaming
private int findFrontCamera(){
int cameraCount = 0;
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
cameraCount = Camera.getNumberOfCameras();
for ( int camIdx = 0; camIdx < cameraCount;camIdx++ ) {
Camera.getCameraInfo( camIdx, cameraInfo );
if ( cameraInfo.facing ==Camera.CameraInfo.CAMERA_FACING_FRONT ) {
return camIdx;
}
}
return -1;
}
代码示例来源:origin: daniulive/SmarterStreaming
@SuppressLint("NewApi")
private Camera openCamera(int type){
int frontIndex =-1;
int backIndex = -1;
int cameraCount = Camera.getNumberOfCameras();
Log.i(TAG, "cameraCount: " + cameraCount);
CameraInfo info = new CameraInfo();
for(int cameraIndex = 0; cameraIndex<cameraCount; cameraIndex++){
Camera.getCameraInfo(cameraIndex, info);
if(info.facing == CameraInfo.CAMERA_FACING_FRONT){
frontIndex = cameraIndex;
}else if(info.facing == CameraInfo.CAMERA_FACING_BACK){
backIndex = cameraIndex;
}
}
pushCurrentCameraType = type;
if(type == FRONT && frontIndex != -1){
pushCurCameraIndex = frontIndex;
return Camera.open(frontIndex);
}else if(type == BACK && backIndex != -1){
pushCurCameraIndex = backIndex;
return Camera.open(backIndex);
}
return null;
}
代码示例来源:origin: nekocode/CameraFilter
private Pair<Camera.CameraInfo, Integer> getBackCamera() {
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
final int numberOfCameras = Camera.getNumberOfCameras();
for (int i = 0; i < numberOfCameras; ++i) {
Camera.getCameraInfo(i, cameraInfo);
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
return new Pair<>(cameraInfo, i);
}
}
return null;
}
}
代码示例来源:origin: daniulive/SmarterStreaming
@SuppressLint("NewApi")
private Camera openCamera(int type) {
int frontIndex = -1;
int backIndex = -1;
int cameraCount = Camera.getNumberOfCameras();
Log.i(TAG, "cameraCount: " + cameraCount);
CameraInfo info = new CameraInfo();
for (int cameraIndex = 0; cameraIndex < cameraCount; cameraIndex++) {
Camera.getCameraInfo(cameraIndex, info);
if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
frontIndex = cameraIndex;
} else if (info.facing == CameraInfo.CAMERA_FACING_BACK) {
backIndex = cameraIndex;
}
}
currentCameraType = type;
if (type == FRONT && frontIndex != -1) {
curCameraIndex = frontIndex;
return Camera.open(frontIndex);
} else if (type == BACK && backIndex != -1) {
curCameraIndex = backIndex;
return Camera.open(backIndex);
}
return null;
}
代码示例来源:origin: daniulive/SmarterStreaming
@SuppressLint("NewApi")
private Camera openCamera(int type){
int frontIndex =-1;
int backIndex = -1;
int cameraCount = Camera.getNumberOfCameras();
Log.i(TAG, "cameraCount: " + cameraCount);
CameraInfo info = new CameraInfo();
for(int cameraIndex = 0; cameraIndex<cameraCount; cameraIndex++){
Camera.getCameraInfo(cameraIndex, info);
if(info.facing == CameraInfo.CAMERA_FACING_FRONT){
frontIndex = cameraIndex;
}else if(info.facing == CameraInfo.CAMERA_FACING_BACK){
backIndex = cameraIndex;
}
}
currentCameraType = type;
if(type == FRONT && frontIndex != -1){
curCameraIndex = frontIndex;
return Camera.open(frontIndex);
}else if(type == BACK && backIndex != -1){
curCameraIndex = backIndex;
return Camera.open(backIndex);
}
return null;
}
代码示例来源:origin: dm77/barcodescanner
/** Favor back-facing camera by default. If none exists, fallback to whatever camera is available **/
public static int getDefaultCameraId() {
int numberOfCameras = Camera.getNumberOfCameras();
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
int defaultCameraId = -1;
for (int i = 0; i < numberOfCameras; i++) {
defaultCameraId = i;
Camera.getCameraInfo(i, cameraInfo);
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
return i;
}
}
return defaultCameraId;
}
代码示例来源:origin: googlesamples/android-vision
/**
* Gets the id for the camera specified by the direction it is facing. Returns -1 if no such
* camera was found.
*
* @param facing the desired camera (front-facing or rear-facing)
*/
private static int getIdForRequestedCamera(int facing) {
CameraInfo cameraInfo = new CameraInfo();
for (int i = 0; i < Camera.getNumberOfCameras(); ++i) {
Camera.getCameraInfo(i, cameraInfo);
if (cameraInfo.facing == facing) {
return i;
}
}
return -1;
}
代码示例来源:origin: googlesamples/android-vision
/**
* Gets the id for the camera specified by the direction it is facing. Returns -1 if no such
* camera was found.
*
* @param facing the desired camera (front-facing or rear-facing)
*/
private static int getIdForRequestedCamera(int facing) {
CameraInfo cameraInfo = new CameraInfo();
for (int i = 0; i < Camera.getNumberOfCameras(); ++i) {
Camera.getCameraInfo(i, cameraInfo);
if (cameraInfo.facing == facing) {
return i;
}
}
return -1;
}
代码示例来源:origin: googlesamples/android-vision
/**
* Gets the id for the camera specified by the direction it is facing. Returns -1 if no such
* camera was found.
*
* @param facing the desired camera (front-facing or rear-facing)
*/
private static int getIdForRequestedCamera(int facing) {
CameraInfo cameraInfo = new CameraInfo();
for (int i = 0; i < Camera.getNumberOfCameras(); ++i) {
Camera.getCameraInfo(i, cameraInfo);
if (cameraInfo.facing == facing) {
return i;
}
}
return -1;
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testCameraInfoNoCameras() throws Exception {
assertThat(Camera.getNumberOfCameras()).isEqualTo(0);
}
代码示例来源:origin: florent37/CameraFragment
@Override
public void initializeCameraManager(ConfigurationProvider configurationProvider, Context context) {
super.initializeCameraManager(configurationProvider, context);
numberOfCameras = Camera.getNumberOfCameras();
for (int i = 0; i < numberOfCameras; ++i) {
final Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
Camera.getCameraInfo(i, cameraInfo);
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
faceBackCameraId = i;
faceBackCameraOrientation = cameraInfo.orientation;
} else if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
faceFrontCameraId = i;
faceFrontCameraOrientation = cameraInfo.orientation;
}
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testCameraInfoBackOnly() throws Exception {
Camera.CameraInfo cameraQuery = new Camera.CameraInfo();
addBackCamera();
Camera.getCameraInfo(0, cameraQuery);
assertThat(Camera.getNumberOfCameras()).isEqualTo(1);
assertThat(cameraQuery.facing).isEqualTo(Camera.CameraInfo.CAMERA_FACING_BACK);
assertThat(cameraQuery.orientation).isEqualTo(0);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testCameraInfoBackAndFront() throws Exception {
Camera.CameraInfo cameraQuery = new Camera.CameraInfo();
addBackCamera();
addFrontCamera();
assertThat(Camera.getNumberOfCameras()).isEqualTo(2);
Camera.getCameraInfo(0, cameraQuery);
assertThat(cameraQuery.facing).isEqualTo(Camera.CameraInfo.CAMERA_FACING_BACK);
assertThat(cameraQuery.orientation).isEqualTo(0);
Camera.getCameraInfo(1, cameraQuery);
assertThat(cameraQuery.facing).isEqualTo(Camera.CameraInfo.CAMERA_FACING_FRONT);
assertThat(cameraQuery.orientation).isEqualTo(90);
}
内容来源于网络,如有侵权,请联系作者删除!