Java 类android.hardware.Camera.CameraInfo 实例源码

项目:react-native-webrtc    文件:WebRTCModule.java   
@SuppressWarnings("deprecation")
public WritableMap getCameraInfo(int index) {
    CameraInfo info = new CameraInfo();

    Size size = null;
    try {
        Camera.getCameraInfo(index, info);
        Camera camera = Camera.open(index);
        size = getMaxSupportedVideoSize(camera);
        camera.release();
    } catch (Exception var3) {
        Logging.e("CameraEnumerationAndroid", "getCameraInfo failed on index " + index, var3);

        return null;
    }
    WritableMap params = Arguments.createMap();
    String facing = info.facing == 1 ? "front" : "back";
    params.putString("label", "Camera " + index + ", Facing " + facing + ", Orientation " + info.orientation);
    params.putString("id", "" + index);
    params.putString("facing", facing);
    params.putString("kind", "video");
    params.putString("maxWidth", String.valueOf(size.width));
    params.putString("maxHeight", String.valueOf(size.height));

    return params;
}
项目:VIQET-Android    文件:CameraActivity.java   
private int findBackFacingCamera() 
{
        int cameraId = -1;
    int numberOfCameras = Camera.getNumberOfCameras();
    for (int i = 0; i < numberOfCameras; i++) 
    {
        CameraInfo info = new CameraInfo();
        Camera.getCameraInfo(i, info);
        if (info.facing == CameraInfo.CAMERA_FACING_BACK)
        {
            Log.d(TAG_NAME, "Camera found");
            cameraId = i;
            break;
        }
    }
    return cameraId;
}
项目:PeSanKita-android    文件:CameraUtils.java   
public static int getCameraDisplayOrientation(@NonNull Activity activity,
                                              @NonNull CameraInfo info)
{
  int            rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
  int            degrees  = 0;
  DisplayMetrics dm       = new DisplayMetrics();

  activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

  switch (rotation) {
  case Surface.ROTATION_0:   degrees = 0;   break;
  case Surface.ROTATION_90:  degrees = 90;  break;
  case Surface.ROTATION_180: degrees = 180; break;
  case Surface.ROTATION_270: degrees = 270; break;
  }

  if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
    return (360 - ((info.orientation + degrees) % 360)) % 360;
  } else {
    return (info.orientation - degrees + 360) % 360;
  }
}
项目:Nird2    文件:CameraView.java   
@UiThread
private void setDisplayOrientation(int rotationDegrees) {
    int orientation;
    CameraInfo info = new CameraInfo();
    Camera.getCameraInfo(0, info);
    if (info.facing == CAMERA_FACING_FRONT) {
        orientation = (info.orientation + rotationDegrees) % 360;
        orientation = (360 - orientation) % 360;
    } else {
        orientation = (info.orientation - rotationDegrees + 360) % 360;
    }
    if (LOG.isLoggable(INFO))
        LOG.info("Display orientation " + orientation + " degrees");
    try {
        camera.setDisplayOrientation(orientation);
    } catch (RuntimeException e) {
        LOG.log(WARNING, "Error setting display orientation", e);
    }
    displayOrientation = orientation;
}
项目:Nird2    文件:CameraView.java   
@UiThread
private void setDisplayOrientation(int rotationDegrees) {
    int orientation;
    CameraInfo info = new CameraInfo();
    Camera.getCameraInfo(0, info);
    if (info.facing == CAMERA_FACING_FRONT) {
        orientation = (info.orientation + rotationDegrees) % 360;
        orientation = (360 - orientation) % 360;
    } else {
        orientation = (info.orientation - rotationDegrees + 360) % 360;
    }
    if (LOG.isLoggable(INFO))
        LOG.info("Display orientation " + orientation + " degrees");
    try {
        camera.setDisplayOrientation(orientation);
    } catch (RuntimeException e) {
        LOG.log(WARNING, "Error setting display orientation", e);
    }
    displayOrientation = orientation;
}
项目:VideoRecorder-master    文件:Util.java   
public static int determineDisplayOrientation(Activity activity, int defaultCameraId) {
    int displayOrientation = 0;
    if(Build.VERSION.SDK_INT >  Build.VERSION_CODES.FROYO)
    {
        CameraInfo cameraInfo = new CameraInfo();
        Camera.getCameraInfo(defaultCameraId, cameraInfo);

        int degrees  = getRotationAngle(activity);


        if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
            displayOrientation = (cameraInfo.orientation + degrees) % 360;
            displayOrientation = (360 - displayOrientation) % 360;
        } else {
            displayOrientation = (cameraInfo.orientation - degrees + 360) % 360;
        }
    }
    return displayOrientation;
}
项目:buildAPKsSamples    文件:CameraFragment.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Create a container that will hold a SurfaceView for camera previews
    mPreview = new Preview(this.getActivity());

    // Find the total number of cameras available
    mNumberOfCameras = Camera.getNumberOfCameras();

    // Find the ID of the rear-facing ("default") camera
    CameraInfo cameraInfo = new CameraInfo();
    for (int i = 0; i < mNumberOfCameras; i++) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
            mCurrentCamera = mDefaultCameraId = i;
        }
    }
    setHasOptionsMenu(mNumberOfCameras > 1);
}
项目:mao-android    文件:BaseCameraView.java   
private void init() {
    setEGLContextClientVersion(2);
    setEGLConfigChooser(8, 8, 8, 8, 16, 0);
    getHolder().setFormat(PixelFormat.RGBA_8888);
    setRenderer(this);
    setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

    float[] cube = OpenGLUtils.CUBE;
    mCubeBuffer = ByteBuffer.allocateDirect(cube.length * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
    mCubeBuffer.put(cube);

    float[] textureCords = OpenGLUtils.getTextureCords(90, mCameraId == CameraInfo.CAMERA_FACING_FRONT, true);
    mTextureBuffer = ByteBuffer.allocateDirect(textureCords.length * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
    mTextureBuffer.put(textureCords);

    List<CameraFilter> filters = new ArrayList<>();
    filters.add(mCameraInputFilter);
    filters.addAll(initFilters());
    mCameraFilterGroup = new CameraFilterGroup(filters);
}
项目:boohee_v5.6    文件:CameraPreview.java   
public int getDisplayOrientation() {
    CameraInfo info = new CameraInfo();
    Camera.getCameraInfo(0, info);
    int degrees = 0;
    switch (((WindowManager) getContext().getSystemService("window")).getDefaultDisplay().getRotation()) {
        case 0:
            degrees = 0;
            break;
        case 1:
            degrees = 90;
            break;
        case 2:
            degrees = 180;
            break;
        case 3:
            degrees = 270;
            break;
    }
    if (info.facing == 1) {
        return (360 - ((info.orientation + degrees) % 360)) % 360;
    }
    return ((info.orientation - degrees) + 360) % 360;
}
项目:Cable-Android    文件:CameraUtils.java   
public static int getCameraDisplayOrientation(@NonNull Activity activity,
                                              @NonNull CameraInfo info)
{
  int            rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
  int            degrees  = 0;
  DisplayMetrics dm       = new DisplayMetrics();

  activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

  switch (rotation) {
  case Surface.ROTATION_0:   degrees = 0;   break;
  case Surface.ROTATION_90:  degrees = 90;  break;
  case Surface.ROTATION_180: degrees = 180; break;
  case Surface.ROTATION_270: degrees = 270; break;
  }

  if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
    return (360 - ((info.orientation + degrees) % 360)) % 360;
  } else {
    return (info.orientation - degrees + 360) % 360;
  }
}
项目:okwallet    文件:CameraManager.java   
private int determineCameraId() {
    final int cameraCount = Camera.getNumberOfCameras();
    final CameraInfo cameraInfo = new CameraInfo();

    // prefer back-facing camera
    for (int i = 0; i < cameraCount; i++) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK)
            return i;
    }

    // fall back to front-facing camera
    for (int i = 0; i < cameraCount; i++) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT)
            return i;
    }

    return -1;
}
项目:GCSApp    文件:RecorderVideoActivity.java   
@SuppressLint("NewApi")
private boolean initCamera() {
    try {
        if (frontCamera == 0) {
            mCamera = Camera.open(CameraInfo.CAMERA_FACING_BACK);
        } else {
            mCamera = Camera.open(CameraInfo.CAMERA_FACING_FRONT);
        }
        Parameters camParams = mCamera.getParameters();
        mCamera.lock();
        mSurfaceHolder = mVideoView.getHolder();
        mSurfaceHolder.addCallback(this);
        mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        mCamera.setDisplayOrientation(90);

    } catch (RuntimeException ex) {
        EMLog.e("video", "init Camera fail " + ex.getMessage());
        return false;
    }
    return true;
}
项目:Android_Video_Recording_portrait    文件:VideoCaptureActivity.java   
private int findBackFacingCamera() {
    cameraId = -1;
    // Search for the back facing camera
    // get the number of cameras
    int numberOfCameras = Camera.getNumberOfCameras();
    // for every camera check
    for (int i = 0; i < numberOfCameras; i++) {
        CameraInfo info = new CameraInfo();
        Camera.getCameraInfo(i, info);
        if (info.facing == CameraInfo.CAMERA_FACING_BACK) {
            cameraId = i;
            cameraFront = false;
            break;
        }
    }
    return cameraId;
}
项目:AndroidCamera    文件:ActivityCamera.java   
private void setUpCamera(final int id) {
    mCameraInstance = getCameraInstance(id);
    Parameters parameters = mCameraInstance.getParameters();
    // TODO adjust by getting supportedPreviewSizes and then choosing
    // the best one for screen size (best fill screen)
    if (parameters.getSupportedFocusModes().contains(
            Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
        parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
    }
    mCameraInstance.setParameters(parameters);

    int orientation = mCameraHelper.getCameraDisplayOrientation(
            ActivityCamera.this, mCurrentCameraId);
    CameraInfo2 cameraInfo = new CameraInfo2();
    mCameraHelper.getCameraInfo(mCurrentCameraId, cameraInfo);
    boolean flipHorizontal = cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT;
    mGPUImage.setUpCamera(mCameraInstance, orientation, flipHorizontal, false);
}
项目:VideoRecord    文件:MyCameraManager.java   
@SuppressLint("NewApi")
public void switchCamera(SurfaceHolder mHolder) {
    if(mCamera != null)
    {
        mCamera.stopPreview();
        mCamera.release();
        if (currentCamera == CameraInfo.CAMERA_FACING_BACK) {
            currentCamera = CameraInfo.CAMERA_FACING_FRONT;
        } else {
            currentCamera = CameraInfo.CAMERA_FACING_BACK;
        }

        mCamera = Camera.open(currentCamera);

        try {
            mCamera.setPreviewDisplay(mHolder);
            cameraDisplayOrientation = CameraHelper.getCameraDisplayOrientation(
                    (Activity)mContext, currentCamera);
            mCamera.setDisplayOrientation(cameraDisplayOrientation);

            mCamera.startPreview();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
项目:ChatDemoUI3.0    文件:RecorderVideoActivity.java   
@SuppressLint("NewApi")
private boolean initCamera() {
    try {
        if (frontCamera == 0) {
            mCamera = Camera.open(CameraInfo.CAMERA_FACING_BACK);
        } else {
            mCamera = Camera.open(CameraInfo.CAMERA_FACING_FRONT);
        }
        Camera.Parameters camParams = mCamera.getParameters();
        mCamera.lock();
        mSurfaceHolder = mVideoView.getHolder();
        mSurfaceHolder.addCallback(this);
        mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        mCamera.setDisplayOrientation(90);

    } catch (RuntimeException ex) {
        EMLog.e("video", "init Camera fail " + ex.getMessage());
        return false;
    }
    return true;
}
项目:LivePublisher    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    button01 = (Button) findViewById(R.id.button_first);
    button01.setOnClickListener(this);
    findViewById(R.id.button_take).setOnClickListener(
            new OnClickListener() {

                @Override
                public void onClick(View v) {
                    livePusher.switchCamera();
                }
            });
    mSurfaceView = (SurfaceView) this.findViewById(R.id.surface);
    mSurfaceHolder = mSurfaceView.getHolder();
    mSurfaceHolder.addCallback(this);
    livePusher = new LivePusher(this, 960, 720, 1024000, 15,
            CameraInfo.CAMERA_FACING_FRONT);
    livePusher.setLiveStateChangeListener(this);
    livePusher.prepare(mSurfaceHolder);

}
项目:SocialPaka    文件:CameraSource.java   
/**
 * 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;
}
项目:PeSanKita-android    文件:CameraView.java   
public void flipCamera() {
  if (Camera.getNumberOfCameras() > 1) {
    cameraId = cameraId == CameraInfo.CAMERA_FACING_BACK
               ? CameraInfo.CAMERA_FACING_FRONT
               : CameraInfo.CAMERA_FACING_BACK;
    onPause();
    onResume();
    TextSecurePreferences.setDirectCaptureCameraId(getContext(), cameraId);
  }
}
项目:PeSanKita-android    文件:CameraView.java   
private int getCameraPictureOrientation() {
  if (getActivity().getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
    outputOrientation = getCameraPictureRotation(getActivity().getWindowManager()
                                                              .getDefaultDisplay()
                                                              .getOrientation());
  } else if (getCameraInfo().facing == CameraInfo.CAMERA_FACING_FRONT) {
    outputOrientation = (360 - displayOrientation) % 360;
  } else {
    outputOrientation = displayOrientation;
  }

  return outputOrientation;
}
项目:PeSanKita-android    文件:CameraView.java   
public int getCameraPictureRotation(int orientation) {
  final CameraInfo info = getCameraInfo();
  final int        rotation;

  orientation = (orientation + 45) / 90 * 90;

  if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
    rotation = (info.orientation - orientation + 360) % 360;
  } else {
    rotation = (info.orientation + orientation) % 360;
  }

  return rotation;
}
项目:PeSanKita-android    文件:CameraView.java   
@Override
protected byte[] doInBackground(byte[]... params) {
  final byte[] data = params[0];
  try {
    return BitmapUtil.createFromNV21(data,
                                     previewSize.width,
                                     previewSize.height,
                                     rotation,
                                     croppingRect,
                                     cameraId == CameraInfo.CAMERA_FACING_FRONT);
  } catch (IOException e) {
    Log.w(TAG, e);
    return null;
  }
}
项目:BuddyBook    文件:CameraSource.java   
/**
 * 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;
}
项目:tensorflow-classifier-android    文件:LegacyCameraConnectionFragment.java   
private int getCameraId() {
  CameraInfo ci = new CameraInfo();
  for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
    Camera.getCameraInfo(i, ci);
    if (ci.facing == CameraInfo.CAMERA_FACING_BACK)
      return i;
  }
  return -1; // No camera found
}
项目:AndroidUvcCameras    文件:CameraService.java   
private static int getCameraType(int orient, int camid) {
    int type = 0;
    boolean isFront = false;

    CameraInfo cameraInfo = new CameraInfo();
    Camera.getCameraInfo(camid, cameraInfo);
    if (cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT) {
        isFront = true;
    }

    if (orient == 90) {
        if (isFront) {
            type = 0;
        } else {
            type = 1;
        }
    } else if (orient == 0) {
        type = 2;
    } else if (orient == 180) {
        type = 3;
    } else if (orient == 270) {
        if (isFront) {
            type = 1;
        } else {
            type = 0;
        }
    }
    return type;
}
项目:AndroidUvcCameras    文件:CameraPreviewNormal.java   
private int getCamId(int type) {
    int n = Camera.getNumberOfCameras();
    for (int i = 0; i < n; i++) {
        CameraInfo cameraInfo = new CameraInfo();
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == type) {
            return i;
        }
    }
    return -1;
}
项目:OCR-Reader    文件:CameraSource.java   
/**
 * 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;
}
项目:Camera2Vision    文件:CameraSource.java   
/**
 * 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;
}
项目:Camera2Vision    文件:CameraSource.java   
/**
 * Calculates the correct rotation for the given camera id and sets the rotation in the
 * parameters.  It also sets the camera's display orientation and rotation.
 *
 * @param parameters the camera parameters for which to set the rotation
 * @param cameraId   the camera id to set rotation based on
 */
private void setRotation(Camera camera, Camera.Parameters parameters, int cameraId) {
    WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    int degrees = 0;
    switch (windowManager.getDefaultDisplay().getRotation()) {
        case Surface.ROTATION_0:
            degrees = 0;
            break;
        case Surface.ROTATION_90:
            degrees = 90;
            break;
        case Surface.ROTATION_180:
            degrees = 180;
            break;
        case Surface.ROTATION_270:
            degrees = 270;
            break;
        default:
            Log.e(TAG, "Bad rotation value");
    }

    CameraInfo cameraInfo = new CameraInfo();
    Camera.getCameraInfo(cameraId, cameraInfo);

    int angle;
    int displayAngle;
    if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        angle = (cameraInfo.orientation + degrees) % 360;
        displayAngle = (360 - angle) % 360; // compensate for it being mirrored
    } else {  // back-facing
        angle = (cameraInfo.orientation - degrees + 360) % 360;
        displayAngle = angle;
    }

    // This corresponds to the rotation constants in {@link Frame}.
    mRotation = angle / 90;

    camera.setDisplayOrientation(displayAngle);
    parameters.setRotation(angle);
}
项目:Fatigue-Detection    文件:CameraOverlapFragment.java   
private void openCamera(int CameraFacing){
        if (null != mCamera) {
            mCamera.setPreviewCallback(null);
            mCamera.stopPreview();
            mCamera.release();
            mCamera = null;
        }
        CameraInfo info = new CameraInfo();
        for(int i = 0; i < Camera.getNumberOfCameras(); i++) {
            Camera.getCameraInfo(i, info);
            if(info.facing == CameraFacing) {
                try{
                    mCamera = Camera.open(i);
                    mCameraInfo = info;
                } catch(RuntimeException e) {
                    e.printStackTrace();
                    mCamera = null;
                    continue;
                }
                break;
            }
        }
        try {
            Log.i(TAG, "SurfaceHolder.Callback?surface Created");
            mCamera.setPreviewDisplay(mSurfaceHolder);// set the surface to be used for live preview
            initCamera();
        } catch (Exception ex) {
            if (null != mCamera) {
                mCamera.release();
                mCamera = null;
            }
//          Log.i(TAG + "initCamera", ex.getMessage());
        }
    }
项目:VideoRecorder-master    文件:FFmpegRecorderActivity.java   
private boolean setCamera() {
    try {

        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) {
            int numberOfCameras = Camera.getNumberOfCameras();

            CameraInfo cameraInfo = new CameraInfo();
            for (int i = 0; i < numberOfCameras; i++) {
                Camera.getCameraInfo(i, cameraInfo);
                if (cameraInfo.facing == cameraSelection) {
                    defaultCameraId = i;
                }
            }
        }
        stopPreview();
        if (mCamera != null)
            mCamera.release();

        if (defaultCameraId >= 0)
            cameraDevice = Camera.open(defaultCameraId);
        else
            cameraDevice = Camera.open();

    } catch (Exception e) {
        return false;
    }
    return true;
}
项目:DeepImagePreview-Project    文件:CameraSource.java   
/**
 * 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;
}
项目:Barcode-Reader    文件:CameraSource.java   
/**
 * 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;
}
项目:ComponentProjectDemo    文件:CameraActivity.java   
private void CameraTrans(SurfaceHolder mholder) {
    // 切换前后摄像头
    int cameraCount = 0;
    CameraInfo cameraInfo = new CameraInfo();
    cameraCount = Camera.getNumberOfCameras();// 得到摄像头的个数

    for (int i = 0; i < cameraCount; i++) {
        Camera.getCameraInfo(i, cameraInfo);// 得到每一个摄像头的信息
        if (startFontCamera) {
            // 现在是后置,变更为前置
            if (cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT) {
                /**
                 * 记得释放camera,方便其他应用调用
                 */
                releaseCamera();
                // 打开当前选中的摄像头
                mcamera = Camera.open(i);
                startFontCamera = false;
                setStartPreview(mcamera, mholder);
                break;
            }
        } else {
            // 现在是前置, 变更为后置
            if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
                /**
                 * 记得释放camera,方便其他应用调用
                 */
                releaseCamera();
                mcamera = Camera.open(i);
                startFontCamera = true;
                setStartPreview(mcamera, mholder);
                break;
            }
        }

    }
}
项目:Toodoo    文件:CameraSource.java   
/**
 * 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;
}
项目:AndroidOCRFforID    文件:CameraSource.java   
/**
 * 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;
}
项目:mao-android    文件:CameraView.java   
private void setUpCamera() {
    if (mCamera == null) {
        mCamera = Camera.open(mCameraId);
        mRenderer.setRotation(90, mCameraId == CameraInfo.CAMERA_FACING_FRONT, false);
        mRenderer.setUpSurfaceTexture(mCamera);
    }
}
项目:mao-android    文件:CameraGLFragment.java   
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    log.i("onCreateView");
    View rootView = inflater.inflate(R.layout.fragment_cameragl, container, false);

    mPreview = (GLSurfaceView) rootView.findViewById(R.id.camera_preview);
    mCamera = Camera.open(mCameraId);
    mPreview.setEGLContextClientVersion(2);
    CameraRenderer renderer = new CameraRenderer(mPreview, mCamera);
    renderer.setRotation(90, mCameraId == CameraInfo.CAMERA_FACING_FRONT, false);
    mPreview.setRenderer(renderer);
    mPreview.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
    return rootView;
}
项目:MegviiFacepp-Android-SDK    文件:ICamera.java   
/**
 * 打开相机
 */
public Camera openCamera(boolean isBackCamera, Activity activity,
                         HashMap<String, Integer> resolutionMap) {
    try {
        if (isBackCamera)
            cameraId = 0;
        else
            cameraId = 1;

        int width = 640;
        int height = 480;

        if (resolutionMap != null) {
            width = resolutionMap.get("width");
            height = resolutionMap.get("height");
        }

        mCamera = Camera.open(cameraId);
        CameraInfo cameraInfo = new CameraInfo();
        Camera.getCameraInfo(cameraId, cameraInfo);
        Camera.Parameters params = mCamera.getParameters();
        // Camera.Size bestPreviewSize = calBestPreviewSize(
        // mCamera.getParameters(), Screen.mWidth, Screen.mHeight);
        Camera.Size bestPreviewSize = calBestPreviewSize(
                mCamera.getParameters(), width, height);
        cameraWidth = bestPreviewSize.width;
        cameraHeight = bestPreviewSize.height;
        params.setPreviewSize(cameraWidth, cameraHeight);
        Angle = getCameraAngle(activity);
        Log.w("ceshi", "Angle==" + Angle);
        Log.d("ceshi", "width = " + cameraWidth + ", height = " + cameraHeight);
        // mCamera.setDisplayOrientation(Angle);
        mCamera.setParameters(params);
        return mCamera;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
项目:MegviiFacepp-Android-SDK    文件:ICamera.java   
/**
 * 获取照相机旋转角度
 */
public int getCameraAngle(Activity activity) {
    int rotateAngle = 90;
    CameraInfo info = new CameraInfo();
    Camera.getCameraInfo(cameraId, info);
    int rotation = activity.getWindowManager().getDefaultDisplay()
            .getRotation();
    int degrees = 0;
    switch (rotation) {
        case Surface.ROTATION_0:
            degrees = 0;
            break;
        case Surface.ROTATION_90:
            degrees = 90;
            break;
        case Surface.ROTATION_180:
            degrees = 180;
            break;
        case Surface.ROTATION_270:
            degrees = 270;
            break;
    }

    if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
        rotateAngle = (info.orientation + degrees) % 360;
        rotateAngle = (360 - rotateAngle) % 360; // compensate the mirror
    } else { // back-facing
        rotateAngle = (info.orientation - degrees + 360) % 360;
    }
    return rotateAngle;
}