Пример #1
0
  public void setCameraPreviewSize(Camera.Parameters cp) {
    List<CameraController.Size> cs = CameraController.getInstance().getSupportedPreviewSizes();

    CameraController.Size os =
        getOptimalPreviewSize(cs, MainScreen.getImageWidth(), MainScreen.getImageHeight());
    cp.setPreviewSize(os.getWidth(), os.getHeight());
    try {
      CameraController.getInstance().setCameraParameters(cp);
    } catch (RuntimeException e) {
      Log.e("CameraTest", "MainScreen.setupCamera unable setParameters " + e.getMessage());
    }
  }
Пример #2
0
  // Used only in old camera interface (HALv3 don't use it)
  public void setCameraPictureSize() {
    Camera camera = CameraController.getCamera();
    if (null == camera) return;

    SharedPreferences prefs =
        PreferenceManager.getDefaultSharedPreferences(MainScreen.getMainContext());
    int jpegQuality = Integer.parseInt(prefs.getString(MainScreen.sJPEGQualityPref, "95"));

    Camera.Parameters cp = CameraController.getInstance().getCameraParameters();
    cp.setPictureSize(MainScreen.getImageWidth(), MainScreen.getImageHeight());
    cp.setJpegQuality(jpegQuality);
    try {
      CameraController.getInstance().setCameraParameters(cp);
    } catch (RuntimeException e) {
      Log.e("CameraTest", "MainScreen.setupCamera unable setParameters " + e.getMessage());
    }
  }
Пример #3
0
  public void selectImageDimension() {
    // ----- Figure how much memory do we have and possibly limit resolution
    long maxMem = Runtime.getRuntime().maxMemory();
    long maxMpix = (maxMem - 1000000) / 3; // 2 x Mpix - result, 1/4 x Mpix
    // x 4 - compressed input jpegs,
    // 1Mb - safe reserve

    // find index selected in preferences
    int prefIdx = -1;
    try {
      prefIdx = Integer.parseInt(MainScreen.getImageSizeIndex());
    } catch (IndexOutOfBoundsException e) {
      prefIdx = -1;
    }

    List<CameraController.Size> cs = CameraController.getResolutionsSizeList();
    // add 8 Mpix for rear camera for HTC One X
    if (Build.MODEL.contains("HTC One X")) {
      if (!CameraController.isFrontCamera()) {
        CameraController.Size additional = null;
        additional = CameraController.getInstance().new Size(3264, 2448);
        additional.setWidth(3264);
        additional.setHeight(2448);
        cs.add(additional);
      }
    }
    int defaultCaptureIdx = -1;
    long defaultCaptureMpix = 0;
    int defaultCaptureWidth = 0;
    int defaultCaptureHeight = 0;
    long CaptureMpix = 0;
    int CaptureWidth = 0;
    int CaptureHeight = 0;
    int CaptureIdx = -1;
    boolean prefFound = false;

    // figure default resolution
    int ii = 0;
    for (CameraController.Size s : cs) {
      long mpix = (long) s.getWidth() * s.getHeight();

      if ((mpix >= CameraController.MIN_MPIX_SUPPORTED) && (mpix < maxMpix)) {
        if (mpix > defaultCaptureMpix && mpix <= MPIX_8) {
          defaultCaptureIdx = ii;
          defaultCaptureMpix = mpix;
          defaultCaptureWidth = s.getWidth();
          defaultCaptureHeight = s.getHeight();
        }
      }

      ii++;
    }

    ii = 0;
    for (CameraController.Size s : cs) {
      long mpix = (long) s.getWidth() * s.getHeight();

      if ((Integer.parseInt(CameraController.getResolutionsIdxesList().get(ii)) == prefIdx)
          && (mpix >= CameraController.MIN_MPIX_SUPPORTED)) {
        prefFound = true;
        CaptureIdx = ii;
        CaptureMpix = mpix;
        CaptureWidth = s.getWidth();
        CaptureHeight = s.getHeight();
        break;
      }

      if (mpix > CaptureMpix) {
        CaptureIdx = ii;
        CaptureMpix = mpix;
        CaptureWidth = s.getWidth();
        CaptureHeight = s.getHeight();
      }

      ii++;
    }

    // default to about 8Mpix if nothing is set in preferences or maximum
    // resolution is above memory limits
    if (defaultCaptureMpix > 0) {
      if (!prefFound) {
        CaptureIdx = defaultCaptureIdx;
        CaptureMpix = defaultCaptureMpix;
        CaptureWidth = defaultCaptureWidth;
        CaptureHeight = defaultCaptureHeight;
      }
    }

    CameraController.setCameraImageSizeIndex(CaptureIdx);
    MainScreen.setImageWidth(CaptureWidth);
    MainScreen.setImageHeight(CaptureHeight);

    MainScreen.setSaveImageWidth(CaptureWidth);
    MainScreen.setSaveImageHeight(CaptureHeight);
  }