Esempio n. 1
0
  /** 焦点放大 */
  public void zoomIn() {
    if (camera != null && camera.getParameters().isZoomSupported()) {

      Camera.Parameters parameters = camera.getParameters();
      if (parameters.getZoom() >= parameters.getMaxZoom()) {
        return;
      }

      parameters.setZoom(parameters.getZoom() + 1);
      camera.setParameters(parameters);
    }
  }
Esempio n. 2
0
  /** 焦点放小 */
  public void zoomOut() {
    if (camera != null && camera.getParameters().isZoomSupported()) {

      Camera.Parameters parameters = camera.getParameters();
      if (parameters.getZoom() <= 0) {
        return;
      }

      parameters.setZoom(parameters.getZoom() - 1);
      camera.setParameters(parameters);
    }
  }
Esempio n. 3
0
  public int doZoom(float scale) {
    synchronized (mCameraLock) {
      if (mCamera == null) {
        return 0;
      }
      int currentZoom = 0;
      int maxZoom;
      Camera.Parameters parameters = mCamera.getParameters();
      if (!parameters.isZoomSupported()) {
        Log.w(TAG, mContext.getString(R.string.zoom_not_supported));
        return currentZoom;
      }
      maxZoom = parameters.getMaxZoom();

      currentZoom = parameters.getZoom() + 1;
      float newZoom;
      if (scale > 1) {
        newZoom = currentZoom + scale * (maxZoom / 10);
      } else {
        newZoom = currentZoom * scale;
      }
      currentZoom = Math.round(newZoom) - 1;
      if (currentZoom < 0) {
        currentZoom = 0;
      } else if (currentZoom > maxZoom) {
        currentZoom = maxZoom;
      }
      parameters.setZoom(currentZoom);
      mCamera.setParameters(parameters);
      return currentZoom;
    }
  }
 public void zoom(int step) {
   Camera.Parameters parameters = mCamera.getParameters();
   if (!parameters.isZoomSupported()) return;
   int zoom = parameters.getZoom() + step;
   if (zoom > parameters.getMaxZoom()) zoom = parameters.getMaxZoom();
   else if (zoom < 0) zoom = 0;
   parameters.setZoom(zoom);
   String str = parameters.getZoomRatios().get(zoom) + "%";
   zoomText.setText(str);
   mCamera.setParameters(parameters);
 }
  private void initCameraParameters() {
    Camera.Parameters parameters = mCamera.getParameters();
    String mod = Build.MODEL;
    if (Build.VERSION.SDK_INT >= 8) {
      // MZ 180, other 90...
      if ("M9".equalsIgnoreCase(mod) || "MX".equalsIgnoreCase(mod)) {
        setDisplayOrientation(mCamera, 180);
      } else {
        setDisplayOrientation(mCamera, 90);
      }
    } else {
      parameters.set("orientation", "portrait");
      parameters.set("rotation", 90);
    }

    if (cameraCurrentlyLocked == CameraInfo.CAMERA_FACING_FRONT) {
      ismCameraCanFlash = false;
    } else {
      ismCameraCanFlash = true;
    }
    if (!ismCameraCanFlash) {
      mBtnFlash1.setVisibility(View.INVISIBLE);
      mBtnFlash2.setVisibility(View.INVISIBLE);
      mBtnFlash3.setVisibility(View.INVISIBLE);
    } else {
      mBtnFlash1.setVisibility(View.VISIBLE);
    }

    List<String> focusModes = parameters.getSupportedFocusModes();
    if (focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
      // Autofocus mode is supported
      parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
    }

    if (parameters.isZoomSupported()) {
      parameters.setZoom(parameters.getZoom()); // 测试通过
    }
    Camera.Size previewSize = getFitParametersSize(parameters.getSupportedPreviewSizes());
    parameters.setPreviewSize(previewSize.width, previewSize.height);
    Camera.Size pictureSize = getFitParametersSize(parameters.getSupportedPictureSizes());
    parameters.setPictureSize(pictureSize.width, pictureSize.height);

    try {
      mCamera.setParameters(parameters);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 public static void setZoom(Camera.Parameters parameters, double targetZoomRatio) {
   if (parameters.isZoomSupported()) {
     Integer zoom = indexOfClosestZoom(parameters, targetZoomRatio);
     if (zoom == null) {
       return;
     }
     if (parameters.getZoom() == zoom) {
       Log.i(TAG, "Zoom is already set to " + zoom);
     } else {
       Log.i(TAG, "Setting zoom to " + zoom);
       parameters.setZoom(zoom);
     }
   } else {
     Log.i(TAG, "Zoom is not supported");
   }
 }