Ejemplo n.º 1
1
  public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
    // If your preview can change or rotate, take care of those events here.
    // Make sure to stop the preview before resizing or reformatting it.

    if (mHolder.getSurface() == null) {
      // preview surface does not exist
      return;
    }

    // stop preview before making changes
    try {
      mCamera.stopPreview();
    } catch (Exception e) {
      // ignore: tried to stop a non-existent preview
    }

    // set preview size and make any resize, rotate or
    // reformatting changes here

    // start preview with new settings
    try {
      mCamera.setPreviewDisplay(mHolder);

      // reference former
      Camera.Parameters parameters = mCamera.getParameters();
      int capWidth = parameters.getPreviewSize().width;
      int capHeight = parameters.getPreviewSize().height;
      // android.graphics.imageformat
      int pixelformat = parameters.getPreviewFormat();
      PixelFormat pixelinfo = new PixelFormat();
      PixelFormat.getPixelFormatInfo(pixelformat, pixelinfo);
      int cameraIndex = 0;
      boolean frontFacing = false;

      Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
      Camera.getCameraInfo(cameraIndex, cameraInfo);
      if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        frontFacing = true;
      }
      // For the default NV21 format, bitsPerPixel = 12.
      int bufSize = capWidth * capHeight * pixelinfo.bitsPerPixel / 8;

      for (int i = 0; i < 5; i++) {
        mCamera.addCallbackBuffer(new byte[bufSize]);
      }

      mCamera.startPreview();

      nftSimpleActivity.nativeVideoInit(capWidth, capHeight, cameraIndex, frontFacing);
    } catch (Exception e) {
      Log.d(TAG, "Error starting camera preview: " + e.getMessage());
    }
  }
Ejemplo n.º 2
0
  /** 开启相机拍摄 */
  public void startCapture() {
    try {
      cameraInfo = new CameraInfo();
      if (mCamera == null) {
        // mCamera = Camera.open();
        camera_count = Camera.getNumberOfCameras();
        Log.e(TAG, "camera count:" + camera_count);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
          for (int i = 0; i < camera_count; i++) {
            CameraInfo info = new CameraInfo();
            Camera.getCameraInfo(i, info);
            // find front camera
            if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
              Log.e(TAG, "to open front camera");
              mCamera = Camera.open(i);
              Camera.getCameraInfo(i, cameraInfo);
            }
          }
        }
        if (mCamera == null) {
          Log.e(TAG, "AAAAA OPEN camera");
          mCamera = Camera.open();
          Camera.getCameraInfo(0, cameraInfo);
        }
      }

      mCamera.stopPreview();
      mParameters = mCamera.getParameters();
      if (isScreenOriatationPortrait()) {
        if (cameraInfo.orientation == 270 || cameraInfo.orientation == 0)
          mCamera.setDisplayOrientation(90);
        if (cameraInfo.orientation == 90) mCamera.setDisplayOrientation(270);
      } else {
        if (cameraInfo.orientation == 90) mCamera.setDisplayOrientation(180);
      }

      mParameters.setPreviewSize(mwidth, mheight);
      mParameters.setPreviewFrameRate(15);
      mCamera.setParameters(mParameters);
      int mformat = mParameters.getPreviewFormat();
      int bitsperpixel = ImageFormat.getBitsPerPixel(mformat);
      Log.e(TAG, "pzy bitsperpixel: " + bitsperpixel);
      yuv_frame = new byte[mwidth * mheight * bitsperpixel / 8];
      yuv_Rotate90 = new byte[mwidth * mheight * bitsperpixel / 8];
      //            yuv_Rotate90lr = new byte[mwidth * mheight * bitsperpixel / 8];
      mCamera.addCallbackBuffer(yuv_frame);
      // mCamera.setPreviewDisplay(holder);
      mCamera.setPreviewDisplay(localSurfaceHolder);
      mCamera.setPreviewCallbackWithBuffer(this);

      EMVideoCallHelper.getInstance().setResolution(mwidth, mheight);

      mCamera.startPreview();
      Log.d(TAG, "camera start preview");
    } catch (Exception e) {
      e.printStackTrace();
      if (mCamera != null) mCamera.release();
    }
  }
Ejemplo n.º 3
0
  @Override
  public void alignCameraAndDisplayOrientation(WindowManager windowManager) {
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(id, info);
    int rotation = windowManager.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;
    }

    int result;
    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
      result = (info.orientation + degrees) % 360;
      result = (360 - result) % 360; // compensate the mirror
    } else { // back-facing
      result = (info.orientation - degrees + 360) % 360;
    }
    camera.setDisplayOrientation(result);
  }
  void setCameraDisplayOrientation(int cameraId) {
    int rotation = 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;
    }

    int result = 0;

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

    if (info.facing == CameraInfo.CAMERA_FACING_BACK) {
      result = ((360 - degrees) + info.orientation);
    } else if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
      result = ((360 - degrees) - info.orientation);
      result += 360;
    }
    result = result % 360;
    camera.setDisplayOrientation(result);
  }
  /** Opens a rear-facing camera with {@link Camera#open(int)}, if one exists, or opens camera 0. */
  public static 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);
      // CAMERA_FACING_BACK:手机背面的摄像头
      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;
  }
Ejemplo n.º 6
0
 /** A safe way to get an instance of the Camera object. */
 public static Camera getCameraInstance() {
   /*
   Camera c = null;
   try {
       c = Camera.open();
   } catch (Exception e) {
   }
   return c;
   */
   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("Your_TAG", "Camera failed to open: " + e.getLocalizedMessage());
         e.printStackTrace();
       }
     }
   }
   return cam;
 }
  @SuppressWarnings("WrongConstant")
  private void setCameraDisplayOrientation(Camera.Parameters parameters) {
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(getCurrentCameraId(), info);
    final int deviceOrientation = Degrees.getDisplayRotation(getActivity());
    mDisplayOrientation =
        Degrees.getDisplayOrientation(
            info.orientation,
            deviceOrientation,
            info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT);
    Log.d(
        "CameraFragment",
        String.format(
            "Orientations: Sensor = %d˚, Device = %d˚, Display = %d˚",
            info.orientation, deviceOrientation, mDisplayOrientation));

    int previewOrientation;
    if (CameraUtil.isArcWelder()) {
      previewOrientation = 0;
    } else {
      previewOrientation = mDisplayOrientation;
      if (Degrees.isPortrait(deviceOrientation)
          && getCurrentCameraPosition() == CAMERA_POSITION_FRONT)
        previewOrientation = Degrees.mirror(mDisplayOrientation);
    }
    parameters.setRotation(previewOrientation);
    mCamera.setDisplayOrientation(previewOrientation);
  }
Ejemplo n.º 8
0
  /* 確認裝置是否有前置鏡頭 */
  private boolean checkCameraHardware(Context context) {
    if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)) {
      // this device has a camera
      return true;
    } else {
      // no camera on this device
      return false;
    }
  }
  //	/* 開啟相機前至鏡頭設置 */
  private Camera openFrontFacingCameraGingerbread() {
    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 (checkCameraHardware(MainActivity.this)) {
        if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
          try {
            cam = Camera.open(camIdx);
          } catch (RuntimeException e) {
            Log.e(TAG, "Camera failed to open: " + e.getLocalizedMessage());
          }
        }
        if (!checkCameraHardware(MainActivity.this)) {
          if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
            try {
              cam = Camera.open(camIdx);
            } catch (RuntimeException e) {
              Log.e(TAG, "Camera failed to open: " + e.getLocalizedMessage());
            }
          }
        }
      }
    }

    return cam;
  }
Ejemplo n.º 9
0
  @Kroll.method
  @Kroll.getProperty
  public int[] getAvailableCameras() {
    int cameraCount = Camera.getNumberOfCameras();
    if (cameraCount == 0) {
      return null;
    }

    int[] result = new int[cameraCount];

    CameraInfo cameraInfo = new CameraInfo();

    for (int i = 0; i < cameraCount; i++) {
      Camera.getCameraInfo(i, cameraInfo);
      switch (cameraInfo.facing) {
        case CameraInfo.CAMERA_FACING_FRONT:
          result[i] = CAMERA_FRONT;
          break;
        case CameraInfo.CAMERA_FACING_BACK:
          result[i] = CAMERA_REAR;
          break;
        default:
          // This would be odd. As of API level 17,
          // there are just the two options.
          result[i] = -1;
      }
    }

    return result;
  }
  private int getCameraOrientation() {
    Camera.CameraInfo info = new Camera.CameraInfo();
    for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
      Camera.getCameraInfo(i, info);
      if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) break;
    }

    int rotation = 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;
    }

    return (info.orientation - degrees + 360) % 360;
  }
Ejemplo n.º 11
0
  public int getDisplayOrientation() {
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(Camera.CameraInfo.CAMERA_FACING_BACK, info);
    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    int rotation = display.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;
    }

    int result;
    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
      result = (info.orientation + degrees) % 360;
      result = (360 - result) % 360; // compensate the mirror
    } else { // back-facing
      result = (info.orientation - degrees + 360) % 360;
    }
    return result;
  }
Ejemplo n.º 12
0
  public static void setCameraDisplayOrientation(
      Activity activity, int cameraId, android.hardware.Camera camera) {
    android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
    android.hardware.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;
    }

    int result;
    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
      result = (info.orientation + degrees) % 360;
      result = (360 - result) % 360; // compensate the mirror
    } else { // back-facing
      result = (info.orientation - degrees + 360) % 360;
    }
    camera.setDisplayOrientation(result);
  }
Ejemplo n.º 13
0
  public CustomeCamera(
      Activity activity, FrameLayout cameraPreviewLayout, Integer size, Integer quality)
      throws Exception {
    this.activity = activity;
    this.size = size;
    this.quality = quality;

    // Create an instance of Camera
    try {
      mCamera = getCameraInstance();
    } catch (Exception e) {
      throw new Exception(e.getMessage());
    }
    try {
      mCamera.setDisplayOrientation(90);
    } catch (Exception e) {
      Log.d(TAG, e.getMessage());
    }

    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(Camera.CameraInfo.CAMERA_FACING_BACK, info);
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    int degrees = 0;
    switch (rotation) {
      case Surface.ROTATION_0:
        degrees = 0;
        break; // Natural orientation
      case Surface.ROTATION_90:
        degrees = 90;
        break; // Landscape left
      case Surface.ROTATION_180:
        degrees = 180;
        break; // Upside down
      case Surface.ROTATION_270:
        degrees = 270;
        break; // Landscape right
    }
    int rotate = (info.orientation - degrees + 360) % 360;

    // STEP #2: Set the 'rotation' parameter
    Camera.Parameters params = mCamera.getParameters();
    params.setRotation(rotate);

    List<String> focusModes = params.getSupportedFocusModes();
    if (focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
      params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
    }
    if (params.getFocusMode() == Camera.Parameters.FOCUS_MODE_AUTO) autoFocusEnabled = true;
    else autoFocusEnabled = false;

    // TODO for the test
    autoFocusEnabled = false;

    mCamera.setParameters(params);

    // Create our Preview view and set it as the content of our activity.
    mPreview = new CameraPreview(activity, mCamera);
    cameraPreviewLayout.addView(mPreview);
  }
Ejemplo n.º 14
0
  public boolean doesZoomReallyWork() {
    CameraInfo info = new CameraInfo();
    Camera.getCameraInfo(getHost().getCameraId(), info);

    return (getHost()
        .getDeviceProfile()
        .doesZoomActuallyWork(info.facing == CameraInfo.CAMERA_FACING_FRONT));
  }
Ejemplo n.º 15
0
 @TargetApi(Build.VERSION_CODES.GINGERBREAD)
 boolean getBackCameraStatus() {
   Camera.CameraInfo ci = new Camera.CameraInfo();
   for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
     Camera.getCameraInfo(i, ci);
     if (ci.facing == Camera.CameraInfo.CAMERA_FACING_BACK) return true;
   }
   return false; // No front-facing camera found
 }
 private void setBackCameraId() {
   CameraInfo cameraInfo = new CameraInfo();
   for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
     Camera.getCameraInfo(i, cameraInfo);
     if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
       backCameraId = i;
     }
   }
 }
Ejemplo n.º 17
0
 /**
  * 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;
 }
 /**
  * Returns true if camcorder profile exists for the first back-facing camera at the given quality
  * level.
  *
  * @param quality the target quality level for the camcorder profile
  */
 public static boolean hasProfile(int quality) {
   int numberOfCameras = Camera.getNumberOfCameras();
   CameraInfo cameraInfo = new CameraInfo();
   for (int i = 0; i < numberOfCameras; i++) {
     Camera.getCameraInfo(i, cameraInfo);
     if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
       return hasProfile(i, quality);
     }
   }
   return false;
 }
  /**
   * Opens a camera, and attempts to establish preview mode at the specified width and height.
   *
   * <p>Sets mCameraPreviewWidth and mCameraPreviewHeight to the actual width/height of the preview.
   */
  private void openCamera(int desiredWidth, int desiredHeight) {
    if (mCamera != null) {
      throw new RuntimeException("camera already initialized");
    }

    Camera.CameraInfo info = new Camera.CameraInfo();

    // Try to find a back-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) {  //TODO: front
      // facing
      if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
        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");
    }
    mCamera.setDisplayOrientation(90); // TODO: set according to front or back facing

    Camera.Parameters parms = mCamera.getParameters();
    //        parms.setRotation(180);

    CameraUtils.choosePreviewSize(parms, desiredWidth, desiredHeight);

    // Give the camera a hint that we're recording video.  This can have a big
    // impact on frame rate.
    parms.setRecordingHint(true);

    // leave the frame rate set to default
    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";
    }
    TextView text = (TextView) findViewById(R.id.cameraParams_text);
    text.setText(previewFacts);

    mCameraPreviewWidth = mCameraPreviewSize.width;
    mCameraPreviewHeight = mCameraPreviewSize.height;
  }
Ejemplo n.º 20
0
 /**
  * Sets the camera that will be used to capture video. You can call this method at any time and
  * changes will take effect next time you start the stream.
  *
  * @param camera Can be either CameraInfo.CAMERA_FACING_BACK or CameraInfo.CAMERA_FACING_FRONT
  */
 public void setCamera(int camera) {
   CameraInfo cameraInfo = new CameraInfo();
   int numberOfCameras = Camera.getNumberOfCameras();
   for (int i = 0; i < numberOfCameras; i++) {
     Camera.getCameraInfo(i, cameraInfo);
     if (cameraInfo.facing == camera) {
       mCameraId = i;
       break;
     }
   }
 }
Ejemplo n.º 21
0
  @SuppressLint("NewApi")
  public void changeCameraFacing() {
    // 切换前后摄像头
    int cameraCount = 0;
    CameraInfo cameraInfo = new CameraInfo();
    cameraCount = Camera.getNumberOfCameras(); // 得到摄像头的个数

    for (int i = 0; i < cameraCount; i++) {
      Camera.getCameraInfo(i, cameraInfo); // 得到每一个摄像头的信息
      if (cameraPosition == 1) {
        // 现在是后置,变更为前置
        if (cameraInfo.facing
            == Camera.CameraInfo
                .CAMERA_FACING_FRONT) { // 代表摄像头的方位,CAMERA_FACING_FRONT前置      CAMERA_FACING_BACK后置
          mCamera.setPreviewCallback(null);
          mCamera.stopPreview(); // 停掉原来摄像头的预览
          mCamera.release(); // 释放资源
          mCamera = null; // 取消原来摄像头
          mCamera = Camera.open(i); // 打开当前选中的摄像头
          try {
            mCamera.setPreviewDisplay(mHolder); // 通过surfaceview显示取景画面
            initParameters();
          } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
          mCamera.startPreview(); // 开始预览
          cameraPosition = 0;
          break;
        }
      } else {
        // 现在是前置, 变更为后置
        if (cameraInfo.facing
            == Camera.CameraInfo
                .CAMERA_FACING_BACK) { // 代表摄像头的方位,CAMERA_FACING_FRONT前置      CAMERA_FACING_BACK后置
          mCamera.setPreviewCallback(null);
          mCamera.stopPreview(); // 停掉原来摄像头的预览
          mCamera.release(); // 释放资源
          mCamera = null; // 取消原来摄像头
          mCamera = Camera.open(i); // 打开当前选中的摄像头
          try {
            mCamera.setPreviewDisplay(mHolder); // 通过surfaceview显示取景画面
            initParameters();
          } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
          mCamera.startPreview(); // 开始预览
          cameraPosition = 1;
          break;
        }
      }
    }
  }
 private int getCameraId(final int facing) {
   int numberOfCameras = Camera.getNumberOfCameras();
   Camera.CameraInfo info = new Camera.CameraInfo();
   for (int id = 0; id < numberOfCameras; id++) {
     Camera.getCameraInfo(id, info);
     if (info.facing == facing) {
       return id;
     }
   }
   return -1;
 }
Ejemplo n.º 23
0
 /**
  * 得到旋转图片的角度
  *
  * @return
  */
 private int getRotate() {
   CameraInfo info = new CameraInfo();
   Camera.getCameraInfo(cameraCurrentlyLocked, info);
   int r = 0;
   if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
     r = (info.orientation - picture_orientation + 360) % 360;
   } else {
     r = (info.orientation + picture_orientation) % 360;
   }
   return r;
 }
 /**
  * Returns the camcorder profile for the first back-facing camera on the device at the given
  * quality level. If the device has no back-facing camera, this returns null.
  *
  * @param quality the target quality level for the camcorder profile
  */
 public static CamcorderProfile get(int quality) {
   int numberOfCameras = Camera.getNumberOfCameras();
   CameraInfo cameraInfo = new CameraInfo();
   for (int i = 0; i < numberOfCameras; i++) {
     Camera.getCameraInfo(i, cameraInfo);
     if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
       return get(i, quality);
     }
   }
   return (numberOfCameras == 1) ? get(0, quality) : null;
 }
 private boolean tryCreateCamera(int facing) {
   Camera.CameraInfo info = new Camera.CameraInfo();
   for (int nCam = 0; nCam < Camera.getNumberOfCameras(); nCam++) {
     Camera.getCameraInfo(nCam, info);
     if (info.facing == facing) {
       camera = Camera.open(nCam);
       cameraInfo = info;
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 26
0
 /**
  * Possible Picture Orientation fix
  *
  * @param param
  * @param orientation
  */
 public void onOrientationChanged(Parameters param, int orientation) {
   if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN) return;
   CameraInfo info = new CameraInfo();
   Camera.getCameraInfo(0, info);
   orientation = (orientation + 45) / 90 * 90;
   int rotation = 0;
   if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
     rotation = (info.orientation - orientation + 360) % 360;
   } else { // back-facing camera
     rotation = (info.orientation + orientation) % 360;
   }
   param.setRotation(rotation);
 }
  public int getCameraRotation(int cameraId) {
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(cameraId, info);

    mOrientation = (mOrientation + 45) / 90 * 90;
    int rotation = 0;
    if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
      rotation = (info.orientation - mOrientation + 360) % 360;
    } else { // back-facing camera
      rotation = (info.orientation + mOrientation) % 360;
    }

    return rotation;
  }
 /**
  * Checks whether this device support a front camera.
  *
  * @return true if this device support a front camera, false otherwise
  */
 public static boolean hasFrontFacingDevice() {
   for (int i = 0; i < Camera.getNumberOfCameras(); ++i) {
     Camera.CameraInfo info = new Camera.CameraInfo();
     try {
       Camera.getCameraInfo(i, info);
       if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
         return true;
       }
     } catch (Exception e) {
       // do nothing.
     }
   }
   return false;
 }
 private int getDisplayOrientation(int degrees, int cameraId) {
   // See android.hardware.Camera.setDisplayOrientation for
   // documentation.
   Camera.CameraInfo info = new Camera.CameraInfo();
   Camera.getCameraInfo(cameraId, info);
   int result;
   if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
     result = (info.orientation + degrees) % 360;
     result = (360 - result) % 360; // compensate the mirror
   } else { // back-facing
     result = (info.orientation - degrees + 360) % 360;
   }
   return result;
 }
Ejemplo n.º 30
0
 private int findFrontFacingCamera() {
   int cameraId = -1;
   // Search for the front facing camera
   int numberOfCameras = Camera.getNumberOfCameras();
   for (int i = 0; i < numberOfCameras; i++) {
     Camera.CameraInfo info = new Camera.CameraInfo();
     Camera.getCameraInfo(i, info);
     if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
       cameraId = i;
       break;
     }
   }
   return cameraId;
 }