android.hardware.Camera.getCameraInfo()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(613)

本文整理了Java中android.hardware.Camera.getCameraInfo()方法的一些代码示例,展示了Camera.getCameraInfo()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Camera.getCameraInfo()方法的具体详情如下:
包路径:android.hardware.Camera
类名称:Camera
方法名:getCameraInfo

Camera.getCameraInfo介绍

暂无

代码示例

代码示例来源: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: LaiFeng-Android/SopCastComponent

public static int getDisplayOrientation(int cameraId) {
  Camera.CameraInfo info = new Camera.CameraInfo();
  Camera.getCameraInfo(cameraId, info);
  int result;
  if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
    result = (info.orientation) % 360;
    result = (360 - result) % 360;  // compensate the mirror
  } else {  // back-facing
    result = (info.orientation + 360) % 360;
  }
  return result;
}

代码示例来源: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 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

@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: journeyapps/zxing-android-embedded

/**
 * Must be called from camera thread.
 */
public void open() {
  camera = OpenCameraInterface.open(settings.getRequestedCameraId());
  if (camera == null) {
    throw new RuntimeException("Failed to open camera");
  }
  int cameraId = OpenCameraInterface.getCameraId(settings.getRequestedCameraId());
  cameraInfo = new Camera.CameraInfo();
  Camera.getCameraInfo(cameraId, cameraInfo);
}

代码示例来源: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 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);
}

代码示例来源: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 testSetDisplayOrientationUpdatesCameraInfos() {
 addBackCamera();
 addFrontCamera();
 camera = Camera.open(1);
 camera.setDisplayOrientation(180);
 Camera.CameraInfo cameraQuery = new Camera.CameraInfo();
 Camera.getCameraInfo(ShadowCamera.getLastOpenedCameraId(), cameraQuery);
 assertThat(cameraQuery.orientation).isEqualTo(180);
}

相关文章