本文整理汇总了Java中android.hardware.Camera.getNumberOfCameras方法的典型用法代码示例。如果您正苦于以下问题:Java Camera.getNumberOfCameras方法的具体用法?Java Camera.getNumberOfCameras怎么用?Java Camera.getNumberOfCameras使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.hardware.Camera
的用法示例。
在下文中一共展示了Camera.getNumberOfCameras方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: RCTCamera
import android.hardware.Camera; //导入方法依赖的package包/类
private RCTCamera(int deviceOrientation) {
_cameras = new HashMap<>();
_cameraInfos = new HashMap<>();
_cameraTypeToIndex = new HashMap<>();
_actualDeviceOrientation = deviceOrientation;
// map camera types to camera indexes and collect cameras properties
for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(i, info);
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT && _cameraInfos.get(RCTCameraModule.RCT_CAMERA_TYPE_FRONT) == null) {
_cameraInfos.put(RCTCameraModule.RCT_CAMERA_TYPE_FRONT, new CameraInfoWrapper(info));
_cameraTypeToIndex.put(RCTCameraModule.RCT_CAMERA_TYPE_FRONT, i);
acquireCameraInstance(RCTCameraModule.RCT_CAMERA_TYPE_FRONT);
releaseCameraInstance(RCTCameraModule.RCT_CAMERA_TYPE_FRONT);
} else if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK && _cameraInfos.get(RCTCameraModule.RCT_CAMERA_TYPE_BACK) == null) {
_cameraInfos.put(RCTCameraModule.RCT_CAMERA_TYPE_BACK, new CameraInfoWrapper(info));
_cameraTypeToIndex.put(RCTCameraModule.RCT_CAMERA_TYPE_BACK, i);
acquireCameraInstance(RCTCameraModule.RCT_CAMERA_TYPE_BACK);
releaseCameraInstance(RCTCameraModule.RCT_CAMERA_TYPE_BACK);
}
}
}
示例2: doOpenCamera
import android.hardware.Camera; //导入方法依赖的package包/类
public void doOpenCamera(CamOpenOverCallback callback) {
if (DEBUG) Log.i(TAG, "Camera open....");
int numCameras = Camera.getNumberOfCameras();
Camera.CameraInfo info = new Camera.CameraInfo();
for (int i = 0; i < numCameras; i++) {
Camera.getCameraInfo(i, info);
if (info.facing == openCameraId) {
mCamera = Camera.open(i);
break;
}
}
if (mCamera == null) {
if (DEBUG) Log.d(TAG, "No front-facing camera found; opening default");
mCamera = Camera.open(); // opens first back-facing camera
}
if (mCamera == null) {
throw new RuntimeException("Unable to open camera");
}
if (DEBUG) Log.i(TAG, "Camera open over....");
callback.cameraHasOpened();
}
示例3: getCurrentCamera
import android.hardware.Camera; //导入方法依赖的package包/类
/**
* Returns current camera identifier.
*
* @return Camera id.
*/
private int getCurrentCamera() {
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
int cameraCount = Camera.getNumberOfCameras();
for(int camIdx = 0; camIdx < cameraCount; camIdx++) {
Camera.getCameraInfo(camIdx, cameraInfo);
if(mFrontCamera && cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
logi("returning front camera");
return camIdx;
} else if(!mFrontCamera && cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
logi("returning back camera");
return camIdx;
}
}
return -1;
}
示例4: startCamera
import android.hardware.Camera; //导入方法依赖的package包/类
/**
* 打开指定摄像头开始预览,但是并未开始识别
*
* @param cameraFacing
*/
public void startCamera(int cameraFacing) {
if (mCamera != null) {
return;
}
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
for (int cameraId = 0; cameraId < Camera.getNumberOfCameras(); cameraId++) {
Camera.getCameraInfo(cameraId, cameraInfo);
if (cameraInfo.facing == cameraFacing) {
startCameraById(cameraId);
break;
}
}
}
示例5: getCameraIdWithFacing
import android.hardware.Camera; //导入方法依赖的package包/类
public static int getCameraIdWithFacing(int facing){
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
int cameraCount = Camera.getNumberOfCameras();
for (int camIdx = 0; camIdx < cameraCount; camIdx++) {
Camera.getCameraInfo(camIdx, cameraInfo);
if (cameraInfo.facing == facing) {
return camIdx;
}
}
return 0;
}
示例6: getIdForRequestedCamera
import android.hardware.Camera; //导入方法依赖的package包/类
/**
* 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;
}
示例7: open
import android.hardware.Camera; //导入方法依赖的package包/类
/**
* Opens a rear-facing camera with {@link Camera#open(int)}, if one exists, or opens camera 0.
*/
@Override
public Camera open() {
int numCameras = Camera.getNumberOfCameras();
if (numCameras == 0) {
Log.w(TAG, "No cameras!");
return null;
}
int index = 0;
while (index < numCameras) {
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
Camera.getCameraInfo(index, cameraInfo);
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
break;
}
index++;
}
Camera camera;
if (index < numCameras) {
Log.i(TAG, "Opening camera #" + index);
camera = Camera.open(index);
} else {
Log.i(TAG, "No camera facing back; returning camera #0");
camera = Camera.open(0);
}
return camera;
}
示例8: openFrontFacingCameraGingerbread
import android.hardware.Camera; //导入方法依赖的package包/类
private Camera openFrontFacingCameraGingerbread() {
if (mCamera != null) {
queue.removeCallbacks(null);
mCamera.setPreviewCallback(null);
mCamera.stopPreview();
mCamera.release();
}
int cameraCount = 0;
Camera cam = null;
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) {
try {
cam = Camera.open(camIdx);
} catch (RuntimeException e) {
Log.e("cameraS",
"Camera failed to open: " + e.getLocalizedMessage());
}
}
}
// cam.setDisplayOrientation(90);
setCameraDisplayOrientation(Camera.CameraInfo.CAMERA_FACING_FRONT, cam);
if (registeredShieldsIDs.contains(UIShield.COLOR_DETECTION_SHIELD.name()))
cam.setPreviewCallback(previewCallback);
return cam;
}
示例9: isCameraExist
import android.hardware.Camera; //导入方法依赖的package包/类
public static boolean isCameraExist(int cameraId) {
int numberOfCameras = Camera.getNumberOfCameras();
for (int i = 0; i < numberOfCameras; i++) {
Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(i, info);
if (info.facing == cameraId) {
return true;
}
}
return false;
}
示例10: getFrontCameraId
import android.hardware.Camera; //导入方法依赖的package包/类
@SuppressLint("NewApi")
private int getFrontCameraId() {
CameraInfo ci = new CameraInfo();
for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
Camera.getCameraInfo(i, ci);
if (ci.facing == CameraInfo.CAMERA_FACING_FRONT) {
return i;
}
}
return -1; // No front-facing camera found
}
示例11: switchCamera
import android.hardware.Camera; //导入方法依赖的package包/类
@TargetApi(9)
private void switchCamera() {
if (Build.VERSION.SDK_INT >= 9) {
cameraId = (cameraId + 1) % Camera.getNumberOfCameras();
}
resizeSurfaceView();
shutdownCamera();
initCamera();
startPreview();
}
示例12: getAvailableCameras
import android.hardware.Camera; //导入方法依赖的package包/类
public static int[] getAvailableCameras() {
int[] res = new int[Camera.getNumberOfCameras()];
for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
res[i] = i;
}
return res;
}
示例13: open
import android.hardware.Camera; //导入方法依赖的package包/类
/**
* Opens the requested camera with {@link Camera#open(int)}, if one exists.
*
* @param cameraId camera ID of the camera to use. A negative value means
* "no preference"
* @return handle to {@link Camera} that was opened
*/
public static Camera open(int cameraId) {
int numCameras = Camera.getNumberOfCameras();
if (numCameras == 0) {
Log.w(TAG, "No cameras!");
return null;
}
boolean explicitRequest = cameraId >= 0;
if (!explicitRequest) {
// Select a camera if no explicit camera requested
int index = 0;
while (index < numCameras) {
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
Camera.getCameraInfo(index, cameraInfo);
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
break;
}
index++;
}
cameraId = index;
}
Camera camera;
if (cameraId < numCameras) {
Log.i(TAG, "Opening camera #" + cameraId);
camera = Camera.open(cameraId);
} else {
if (explicitRequest) {
Log.w(TAG, "Requested camera does not exist: " + cameraId);
camera = null;
} else {
Log.i(TAG, "No camera facing back; returning camera #0");
camera = Camera.open(0);
}
}
return camera;
}
示例14: switchCamera
import android.hardware.Camera; //导入方法依赖的package包/类
private void switchCamera() {
mCurrentCameraId = (mCurrentCameraId + 1) % Camera.getNumberOfCameras();
releaseCamera();
openCamera(mCurrentCameraId);
}
示例15: openCamera
import android.hardware.Camera; //导入方法依赖的package包/类
/**
* Opens a camera, and attempts to establish preview mode at the specified width
* and height with a fixed frame rate.
* <p>
* Sets mCameraPreviewWidth / mCameraPreviewHeight.
*/
private void openCamera(int desiredWidth, int desiredHeight, int desiredFps) {
if (mCamera != null) {
throw new RuntimeException("camera already initialized");
}
Camera.CameraInfo info = new Camera.CameraInfo();
// Try to find a front-facing camera (e.g. for videoconferencing).
int numCameras = Camera.getNumberOfCameras();
for (int i = 0; i < numCameras; i++) {
Camera.getCameraInfo(i, info);
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
mCamera = Camera.open(i);
break;
}
}
if (mCamera == null) {
Log.d(TAG, "No front-facing camera found; opening default");
mCamera = Camera.open(); // opens first back-facing camera
}
if (mCamera == null) {
throw new RuntimeException("Unable to open camera");
}
Camera.Parameters parms = mCamera.getParameters();
CameraUtils.choosePreviewSize(parms, desiredWidth, desiredHeight);
// Try to set the frame rate to a constant value.
int thousandFps = CameraUtils.chooseFixedPreviewFps(parms, desiredFps * 1000);
// Give the camera a hint that we're recording video. This can have a big
// impact on frame rate.
parms.setRecordingHint(true);
mCamera.setParameters(parms);
int[] fpsRange = new int[2];
Camera.Size mCameraPreviewSize = parms.getPreviewSize();
parms.getPreviewFpsRange(fpsRange);
String previewFacts = mCameraPreviewSize.width + "x" + mCameraPreviewSize.height;
if (fpsRange[0] == fpsRange[1]) {
previewFacts += " @" + (fpsRange[0] / 1000.0) + "fps";
} else {
previewFacts += " @[" + (fpsRange[0] / 1000.0) +
" - " + (fpsRange[1] / 1000.0) + "] fps";
}
Log.i(TAG, "Camera config: " + previewFacts);
mCameraPreviewWidth = mCameraPreviewSize.width;
mCameraPreviewHeight = mCameraPreviewSize.height;
mMainHandler.sendCameraParams(mCameraPreviewWidth, mCameraPreviewHeight,
thousandFps / 1000.0f);
}