當前位置: 首頁>>代碼示例>>Java>>正文


Java Camera.getNumberOfCameras方法代碼示例

本文整理匯總了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);
        }
    }
}
 
開發者ID:jonathan68,項目名稱:react-native-camera,代碼行數:25,代碼來源:RCTCamera.java

示例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();
}
 
開發者ID:Yee-chen,項目名稱:seeta4Android,代碼行數:22,代碼來源:CameraWrapper.java

示例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;
}
 
開發者ID:Samsung,項目名稱:microbit,代碼行數:22,代碼來源:CameraActivity_OldAPI.java

示例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;
        }
    }
}
 
開發者ID:devzwy,項目名稱:NeiHanDuanZiTV,代碼行數:19,代碼來源:QRCodeView.java

示例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;
}
 
開發者ID:zhangyaqiang,項目名稱:Fatigue-Detection,代碼行數:12,代碼來源:CameraEngine.java

示例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;
}
 
開發者ID:EzequielAdrianM,項目名稱:Camera2Vision,代碼行數:17,代碼來源:CameraSource.java

示例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;
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:34,代碼來源:GingerbreadOpenCameraInterface.java

示例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;
    }
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:29,代碼來源:CameraHeadService.java

示例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;
}
 
開發者ID:imjaspreet,項目名稱:Camera-Background-Servce,代碼行數:12,代碼來源:Util.java

示例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
}
 
開發者ID:victordiaz,項目名稱:phonk,代碼行數:12,代碼來源:CustomCameraView.java

示例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();
}
 
開發者ID:newDeepLearing,項目名稱:decoy,代碼行數:11,代碼來源:CaptureVideoActivity.java

示例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;
}
 
開發者ID:Rai220,項目名稱:Telephoto,代碼行數:8,代碼來源:FabricUtils.java

示例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;
}
 
開發者ID:CardInfoLink,項目名稱:QRScanner,代碼行數:49,代碼來源:OpenCameraInterface.java

示例14: switchCamera

import android.hardware.Camera; //導入方法依賴的package包/類
private void switchCamera() {
    mCurrentCameraId = (mCurrentCameraId + 1) % Camera.getNumberOfCameras();
    releaseCamera();
    openCamera(mCurrentCameraId);
}
 
開發者ID:uestccokey,項目名稱:EZFilter,代碼行數:6,代碼來源:CameraFilterActivity.java

示例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);
}
 
開發者ID:AndyZhu1991,項目名稱:grafika,代碼行數:61,代碼來源:TextureFromCameraActivity.java


注:本文中的android.hardware.Camera.getNumberOfCameras方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。