Java 类com.google.zxing.client.android.camera.CameraConfigurationUtils 实例源码

项目:code-scanner    文件:CodeScanner.java   
private void setFlashEnabledInternal(boolean flashEnabled) {
    try {
        DecoderWrapper decoderWrapper = mDecoderWrapper;
        Camera camera = decoderWrapper.getCamera();
        Camera.Parameters parameters = camera.getParameters();
        if (parameters == null) {
            return;
        }
        boolean changed;
        if (flashEnabled) {
            changed = Utils.setFlashMode(parameters, Camera.Parameters.FLASH_MODE_TORCH);
        } else {
            changed = Utils.setFlashMode(parameters, Camera.Parameters.FLASH_MODE_OFF);
        }
        if (changed) {
            CameraConfigurationUtils.setBestExposure(parameters, flashEnabled);
            camera.setParameters(parameters);
        }
    } catch (Exception ignored) {
    }
}
项目:ZXingAndroidExt    文件:CameraConfigurationManager.java   
private void doSetTorch(Camera.Parameters parameters, boolean newSetting, boolean safeMode) {
    CameraConfigurationUtils.setTorch(parameters, newSetting);
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    if (!safeMode && !prefs.getBoolean(PreferencesActivity.KEY_DISABLE_EXPOSURE, true)) {
        CameraConfigurationUtils.setBestExposure(parameters, newSetting);
    }
}
项目:androidscan    文件:CameraConfigurationManager.java   
/**
 * Reads, one time, values from the camera that are needed by the app.
 */
void initFromCameraParameters(Camera camera) {
    Camera.Parameters parameters = camera.getParameters();
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    Point theScreenResolution = new Point();
    theScreenResolution = getDisplaySize(display);

    screenResolution = theScreenResolution;
    Log.i(TAG, "Screen resolution: " + screenResolution);

    Point screenResolutionForCamera = new Point();
    screenResolutionForCamera.x = screenResolution.x;
    screenResolutionForCamera.y = screenResolution.y;

    if (screenResolution.x < screenResolution.y) {
        screenResolutionForCamera.x = screenResolution.y;
        screenResolutionForCamera.y = screenResolution.x;
    }

    cameraResolution = CameraConfigurationUtils.findBestPreviewSizeValue(parameters, screenResolution);
    Log.i(TAG, "Camera resolution x: " + cameraResolution.x);
    Log.i(TAG, "Camera resolution y: " + cameraResolution.y);
}
项目:ZxingSupport    文件:CameraConfig.java   
/**
 * 计算屏幕的尺寸
 *
 * @param camera
 */
private void measureCameraPreviewSize(Camera camera, int width, int height, int rotation) {
    Camera.Parameters parameters = camera.getParameters();
    previewFormat = parameters.getPreviewFormat();
    previewFormatString = parameters.get("preview-format");
    Log.d(TAG, "Default preview format: " + previewFormat + '/' + previewFormatString);

    screenResolution = DeviceUtils.getScreenSize(mContext);
    Log.d(TAG, "Screen resolution: " + screenResolution);

    Point screenResolutionForCamera = new Point();
    screenResolutionForCamera.x = width;
    screenResolutionForCamera.y = height;

    //根据view 的分辨率,计算出相机最适合的分辨率

    cameraResolution = CameraConfigurationUtils.findBestPreviewSizeValue(parameters, screenResolutionForCamera);

    Log.d(TAG, "Camera resolution: " + cameraResolution);
}
项目:attendee-checkin    文件:ScannerManager.java   
private Camera openCamera() {
    Camera.CameraInfo info = new Camera.CameraInfo();
    int id = chooseBackFacingCamera(info);
    Camera camera = Camera.open(id);
    Point screenResolution = new Point();
    camera.setDisplayOrientation((info.orientation - getDisplayInfo(screenResolution) + 360) % 360);
    Camera.Parameters parameters = camera.getParameters();
    CameraConfigurationUtils.setFocus(parameters, true, true, false);
    CameraConfigurationUtils.setBarcodeSceneMode(parameters);
    CameraConfigurationUtils.setVideoStabilization(parameters);
    CameraConfigurationUtils.setFocusArea(parameters);
    CameraConfigurationUtils.setMetering(parameters);
    mCaptureSize = CameraConfigurationUtils.findBestPreviewSizeValue(parameters, screenResolution);
    Log.d(TAG, "Screen resolution: " + screenResolution.x + "x" + screenResolution.y);
    Log.d(TAG, "Preview size: " + mCaptureSize.x + "x" + mCaptureSize.y);
    parameters.setPreviewSize(mCaptureSize.x, mCaptureSize.y);
    camera.setParameters(parameters);
    return camera;
}
项目:droidxing    文件:CameraConfigurationManager.java   
/**
 * Reads, one time, values from the camera that are needed by the app.
 */
void initFromCameraParameters(Camera camera) {
    Camera.Parameters parameters = camera.getParameters();
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    Point theScreenResolution = new Point();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(theScreenResolution);
    } else {
        theScreenResolution.set(display.getWidth(), display.getHeight());
    }
    screenResolution = theScreenResolution;
    Log.i(TAG, "Screen resolution: " + screenResolution);
    cameraResolution = CameraConfigurationUtils
            .findBestPreviewSizeValue(parameters, screenResolution);
    Log.i(TAG, "Camera resolution: " + cameraResolution);
}
项目:androidscan    文件:CameraConfigurationManager.java   
void setDesiredCameraParameters(Camera camera, boolean safeMode) {
    Camera.Parameters parameters = camera.getParameters();
    if (parameters == null) {
        Log.w(TAG, "Device error: no camera parameters are available. Proceeding without configuration.");
        return;
    }

    initializeTorch(parameters, safeMode);

    CameraConfigurationUtils.setFocus(
            parameters,
            true,
            true,
            safeMode);

    if (!safeMode) {
        CameraConfigurationUtils.setBarcodeSceneMode(parameters);
        CameraConfigurationUtils.setVideoStabilization(parameters);
        CameraConfigurationUtils.setFocusArea(parameters);
        CameraConfigurationUtils.setMetering(parameters);
    }

    parameters.setPreviewSize(cameraResolution.x, cameraResolution.y);
    Log.i(TAG, "Final camera parameters: " + parameters.flatten());

    camera.setParameters(parameters);
    Camera.Parameters afterParameters = camera.getParameters();
    Camera.Size afterSize = afterParameters.getPreviewSize();
    if (afterSize != null && (cameraResolution.x != afterSize.width || cameraResolution.y != afterSize.height)) {
        Log.w(TAG, "Camera said it supported preview size " + cameraResolution.x + 'x' + cameraResolution.y +
                ", but after setting it, preview size is " + afterSize.width + 'x' + afterSize.height);
        cameraResolution.x = afterSize.width;
        cameraResolution.y = afterSize.height;
    }

    camera.setDisplayOrientation(90);
}
项目:Zxing-Custom    文件:CameraConfigurationManager.java   
private void doSetTorch(Camera.Parameters parameters, boolean newSetting, boolean safeMode) {
  CameraConfigurationUtils.setTorch(parameters, newSetting);
  SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
  //if (!safeMode && !prefs.getBoolean(PreferencesActivity.KEY_DISABLE_EXPOSURE, true)) {
    CameraConfigurationUtils.setBestExposure(parameters, newSetting);
  //}
}
项目:Android-Barcode    文件:CameraConfigurationManager.java   
/**
 * Reads, one time, values from the camera that are needed by the app.
 */
void initFromCameraParameters(Camera camera) {
    Camera.Parameters parameters = camera.getParameters();
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    Point theScreenResolution = new Point();
    display.getSize(theScreenResolution);
    screenResolution = theScreenResolution;
    Log.i(TAG, "Screen resolution: " + screenResolution);
    cameraResolution = CameraConfigurationUtils.findBestPreviewSizeValue(parameters, screenResolution);
    Log.i(TAG, "Camera resolution: " + cameraResolution);
}
项目:FxExplorer    文件:ScannerActivity.java   
@Override
protected void onResume() {
    super.onResume();
    camera = Camera.open();
    parameters = camera.getParameters();
    DisplayMetrics metric = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metric);
    if (metric.widthPixels < metric.heightPixels){
        camera.setDisplayOrientation(90);
    } else {
        camera.setDisplayOrientation(0);
    }
    CameraConfigurationUtils.setBestPreviewFPS(parameters);
    Log.d(null, "Display Metric:" + metric.widthPixels + "x" + metric.heightPixels);
    Point p = CameraConfigurationUtils.findBestPreviewSizeValue(parameters, new Point(metric.widthPixels, metric.heightPixels));
    setBestPreviewSize(p, metric, parameters);
    List<String> focusMode = parameters.getSupportedFocusModes();

    // 自动对焦优先
    if (focusMode.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
        parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
    } else if (focusMode.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
        parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
    } else if (focusMode.contains(Camera.Parameters.FOCUS_MODE_MACRO)) {
        parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_MACRO);
    } else {
        isSupportAutoFocus = false;
    }
    if (isSupportAutoFocus) {
        autoFocusCallback = new AutoFocusCallBack();
    }
    parameters.setPreviewFormat(ImageFormat.NV21);
    camera.setParameters(parameters);
    previewCallback = new PreviewCallBack();
    camera.setPreviewCallback(previewCallback);
    startPreview();
    camera.startPreview();
}
项目:zxing-bsplus    文件:CameraConfigurationManager.java   
private void doSetTorch(Camera.Parameters parameters, boolean newSetting, boolean safeMode) {
  CameraConfigurationUtils.setTorch(parameters, newSetting);
  SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
  if (!safeMode && !prefs.getBoolean(PreferencesActivity.KEY_DISABLE_EXPOSURE, true)) {
    CameraConfigurationUtils.setBestExposure(parameters, newSetting);
  }
}
项目:casa-glass    文件:CameraConfigurationManager.java   
private static void configureAdvanced(Camera.Parameters parameters) {
    CameraConfigurationUtils.setBestPreviewFPS(parameters);
    CameraConfigurationUtils.setBarcodeSceneMode(parameters);
    CameraConfigurationUtils.setVideoStabilization(parameters);
    CameraConfigurationUtils.setMetering(parameters);
    CameraConfigurationUtils.setZoom(parameters, ZOOM);
}
项目:casa-glass    文件:CameraConfigurationManager.java   
public static void logAllParameters(Camera.Parameters parameters) {
    if (Log.isLoggable(TAG, Log.INFO)) {
        for (String line : CameraConfigurationUtils.collectStats(parameters).split("\n")) {
            Log.i(TAG, line);
        }
    }
}
项目:code-scanner    文件:CodeScanner.java   
private void initialize() {
    Camera camera = null;
    Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
    int cameraId = mCameraId;
    if (cameraId == DEFAULT_CAMERA) {
        int numberOfCameras = Camera.getNumberOfCameras();
        for (int i = 0; i < numberOfCameras; i++) {
            Camera.getCameraInfo(i, cameraInfo);
            if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
                camera = Camera.open(i);
                mCameraId = i;
                break;
            }
        }
    } else {
        camera = Camera.open(cameraId);
        Camera.getCameraInfo(cameraId, cameraInfo);
    }
    if (camera == null) {
        throw new CodeScannerException("Unable to access camera");
    }
    Camera.Parameters parameters = camera.getParameters();
    if (parameters == null) {
        throw new CodeScannerException("Unable to configure camera");
    }
    int orientation = Utils.getDisplayOrientation(mContext, cameraInfo);
    boolean portrait = Utils.isPortrait(orientation);
    Point imageSize =
            Utils.findSuitableImageSize(parameters, portrait ? mHeight : mWidth, portrait ? mWidth : mHeight);
    int imageWidth = imageSize.getX();
    int imageHeight = imageSize.getY();
    parameters.setPreviewSize(imageWidth, imageHeight);
    Point previewSize =
            Utils.getPreviewSize(portrait ? imageHeight : imageWidth, portrait ? imageWidth : imageHeight,
                    mWidth, mHeight);
    List<String> focusModes = parameters.getSupportedFocusModes();
    boolean autoFocusSupported = focusModes != null &&
            (focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO) ||
                    focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE));
    if (!autoFocusSupported) {
        mAutoFocusEnabled = false;
    }
    if (autoFocusSupported && mAutoFocusEnabled) {
        Utils.setAutoFocusMode(parameters, mAutoFocusMode);
    }
    List<String> flashModes = parameters.getSupportedFlashModes();
    boolean flashSupported = flashModes != null && flashModes.contains(Camera.Parameters.FLASH_MODE_TORCH);
    if (!flashSupported) {
        mFlashEnabled = false;
    }
    Utils.optimizeParameters(parameters);
    CameraConfigurationUtils.setBestExposure(parameters, mFlashEnabled);
    camera.setParameters(parameters);
    camera.setDisplayOrientation(orientation);
    mInitializeLock.lock();
    try {
        Decoder decoder = new Decoder(mDecoderStateListener, mFormats, mDecodeCallback);
        mDecoderWrapper = new DecoderWrapper(camera, cameraInfo, decoder, imageSize, previewSize,
                new Point(mWidth, mHeight), orientation, autoFocusSupported, flashSupported);
        decoder.start();
        mInitialization = false;
        mInitialized = true;
    } finally {
        mInitializeLock.unlock();
    }
    mMainThreadHandler.post(new FinishInitializationTask(previewSize));
}
项目:code-scanner    文件:Utils.java   
public static void optimizeParameters(@NonNull Camera.Parameters parameters) {
    CameraConfigurationUtils.setBestPreviewFPS(parameters);
    CameraConfigurationUtils.setBarcodeSceneMode(parameters);
    CameraConfigurationUtils.setVideoStabilization(parameters);
    parameters.setPreviewFormat(ImageFormat.NV21);
}
项目:QrCode    文件:CameraConfigurationManager.java   
private void doSetTorch(Camera.Parameters parameters, boolean newSetting, boolean safeMode) {
  CameraConfigurationUtils.setTorch(parameters, newSetting);
  if (!safeMode && !Config.ConfigType.KEY_DISABLE_EXPOSURE.enable()) {
    CameraConfigurationUtils.setBestExposure(parameters, newSetting);
  }
}
项目:ZXingAndroidExt    文件:CameraConfigurationManager.java   
void setDesiredCameraParameters(OpenCamera camera, boolean safeMode) {

        Camera theCamera = camera.getCamera();
        Camera.Parameters parameters = theCamera.getParameters();

        if (parameters == null) {
            Log.w(TAG, "Device error: no camera parameters are available. Proceeding without configuration.");
            return;
        }

        Log.i(TAG, "Initial camera parameters: " + parameters.flatten());

        if (safeMode) {
            Log.w(TAG, "In camera config safe mode -- most settings will not be honored");
        }

        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

        initializeTorch(parameters, prefs, safeMode);

        CameraConfigurationUtils.setFocus(
                parameters,
                prefs.getBoolean(PreferencesActivity.KEY_AUTO_FOCUS, true),
                prefs.getBoolean(PreferencesActivity.KEY_DISABLE_CONTINUOUS_FOCUS, true),
                safeMode);

        if (!safeMode) {
            if (prefs.getBoolean(PreferencesActivity.KEY_INVERT_SCAN, false)) {
                CameraConfigurationUtils.setInvertColor(parameters);
            }

            if (!prefs.getBoolean(PreferencesActivity.KEY_DISABLE_BARCODE_SCENE_MODE, true)) {
                CameraConfigurationUtils.setBarcodeSceneMode(parameters);
            }

            if (!prefs.getBoolean(PreferencesActivity.KEY_DISABLE_METERING, true)) {
                CameraConfigurationUtils.setVideoStabilization(parameters);
                CameraConfigurationUtils.setFocusArea(parameters);
                CameraConfigurationUtils.setMetering(parameters);
            }

        }

        parameters.setPreviewSize(bestPreviewSize.x, bestPreviewSize.y);

        theCamera.setParameters(parameters);

        theCamera.setDisplayOrientation(cwRotationFromDisplayToCamera);

        Camera.Parameters afterParameters = theCamera.getParameters();
        Camera.Size afterSize = afterParameters.getPreviewSize();
        if (afterSize != null && (bestPreviewSize.x != afterSize.width || bestPreviewSize.y != afterSize.height)) {
            Log.w(TAG, "Camera said it supported preview size " + bestPreviewSize.x + 'x' + bestPreviewSize.y +
                    ", but after setting it, preview size is " + afterSize.width + 'x' + afterSize.height);
            bestPreviewSize.x = afterSize.width;
            bestPreviewSize.y = afterSize.height;
        }
    }
项目:androidscan    文件:CameraConfigurationManager.java   
private void doSetTorch(Camera.Parameters parameters, boolean newSetting, boolean safeMode) {
    CameraConfigurationUtils.setTorch(parameters, newSetting);
    if (!safeMode) {
        CameraConfigurationUtils.setBestExposure(parameters, newSetting);
    }
}
项目:Zxing-Custom    文件:CameraConfigurationManager.java   
void setDesiredCameraParameters(Camera camera, boolean safeMode) {
  Camera.Parameters parameters = camera.getParameters();

  if (parameters == null) {
    Log.w(TAG, "Device error: no camera parameters are available. Proceeding without configuration.");
    return;
  }

  Log.i(TAG, "Initial camera parameters: " + parameters.flatten());

  if (safeMode) {
    Log.w(TAG, "In camera config safe mode -- most settings will not be honored");
  }

  SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

  initializeTorch(parameters, prefs, safeMode);

  CameraConfigurationUtils.setFocus(
          parameters,
          true,
          true,
      safeMode);

  if (!safeMode) {
    //if (prefs.getBoolean(PreferencesActivity.KEY_INVERT_SCAN, false)) {
    //  CameraConfigurationUtils.setInvertColor(parameters);
    //}

    //if (!prefs.getBoolean(PreferencesActivity.KEY_DISABLE_BARCODE_SCENE_MODE, true)) {
    //  CameraConfigurationUtils.setBarcodeSceneMode(parameters);
    //}

    //if (!prefs.getBoolean(PreferencesActivity.KEY_DISABLE_METERING, true)) {
    //  CameraConfigurationUtils.setVideoStabilization(parameters);
    //  CameraConfigurationUtils.setFocusArea(parameters);
    //  CameraConfigurationUtils.setMetering(parameters);
    //}

  }

  parameters.setPreviewSize(cameraResolution.x, cameraResolution.y);

  Log.i(TAG, "Final camera parameters: " + parameters.flatten());

  camera.setParameters(parameters);

  Camera.Parameters afterParameters = camera.getParameters();
  Camera.Size afterSize = afterParameters.getPreviewSize();
  if (afterSize!= null && (cameraResolution.x != afterSize.width || cameraResolution.y != afterSize.height)) {
    Log.w(TAG, "Camera said it supported preview size " + cameraResolution.x + 'x' + cameraResolution.y +
               ", but after setting it, preview size is " + afterSize.width + 'x' + afterSize.height);
    cameraResolution.x = afterSize.width;
    cameraResolution.y = afterSize.height;
  }
}
项目:Android-Barcode    文件:CameraConfigurationManager.java   
void setDesiredCameraParameters(Camera camera, boolean safeMode) {
    Camera.Parameters parameters = camera.getParameters();

    if (parameters == null) {
        Log.w(TAG, "Device error: no camera parameters are available. Proceeding without configuration.");
        return;
    }

    Log.i(TAG, "Initial camera parameters: " + parameters.flatten());

    if (safeMode) {
        Log.w(TAG, "In camera config safe mode -- most settings will not be honored");
    }

    initializeTorch(parameters, safeMode);

    CameraConfigurationUtils.setFocus(
            parameters,
            mZXingConfiguration.getBoolean(ZXingConfiguration.KEY_AUTO_FOCUS, true),
            mZXingConfiguration.getBoolean(ZXingConfiguration.KEY_DISABLE_CONTINUOUS_FOCUS, true),
            safeMode);

    if (!safeMode) {
        if (mZXingConfiguration.getBoolean(ZXingConfiguration.KEY_INVERT_SCAN, false)) {
            CameraConfigurationUtils.setInvertColor(parameters);
        }

        if (!mZXingConfiguration.getBoolean(ZXingConfiguration.KEY_DISABLE_BARCODE_SCENE_MODE, true)) {
            CameraConfigurationUtils.setBarcodeSceneMode(parameters);
        }

        if (!mZXingConfiguration.getBoolean(ZXingConfiguration.KEY_DISABLE_METERING, true)) {
            CameraConfigurationUtils.setVideoStabilization(parameters);
            CameraConfigurationUtils.setFocusArea(parameters);
            CameraConfigurationUtils.setMetering(parameters);
        }

    }

    parameters.setPreviewSize(cameraResolution.x, cameraResolution.y);

    Log.i(TAG, "Final camera parameters: " + parameters.flatten());

    camera.setParameters(parameters);

    Camera.Parameters afterParameters = camera.getParameters();
    Camera.Size afterSize = afterParameters.getPreviewSize();
    if (afterSize != null && (cameraResolution.x != afterSize.width || cameraResolution.y != afterSize.height)) {
        Log.w(TAG, "Camera said it supported preview size " + cameraResolution.x + 'x' + cameraResolution.y +
                ", but after setting it, preview size is " + afterSize.width + 'x' + afterSize.height);
        cameraResolution.x = afterSize.width;
        cameraResolution.y = afterSize.height;
    }
}
项目:Android-Barcode    文件:CameraConfigurationManager.java   
private void doSetTorch(Camera.Parameters parameters, boolean newSetting, boolean safeMode) {
    CameraConfigurationUtils.setTorch(parameters, newSetting);
    if (!safeMode && !mZXingConfiguration.getBoolean(ZXingConfiguration.KEY_DISABLE_EXPOSURE, true)) {
        CameraConfigurationUtils.setBestExposure(parameters, newSetting);
    }
}
项目:zxing-bsplus    文件:CameraConfigurationManager.java   
void setDesiredCameraParameters(OpenCamera camera, boolean safeMode) {

    Camera theCamera = camera.getCamera();
    Camera.Parameters parameters = theCamera.getParameters();

    if (parameters == null) {
      Log.w(TAG, "Device error: no camera parameters are available. Proceeding without configuration.");
      return;
    }

    Log.i(TAG, "Initial camera parameters: " + parameters.flatten());

    if (safeMode) {
      Log.w(TAG, "In camera config safe mode -- most settings will not be honored");
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    initializeTorch(parameters, prefs, safeMode);

    CameraConfigurationUtils.setBestPreviewFPS(parameters);

    CameraConfigurationUtils.setFocus(
        parameters,
        prefs.getBoolean(PreferencesActivity.KEY_AUTO_FOCUS, true),
        prefs.getBoolean(PreferencesActivity.KEY_DISABLE_CONTINUOUS_FOCUS, true),
        safeMode);

    if (!safeMode) {
      if (prefs.getBoolean(PreferencesActivity.KEY_INVERT_SCAN, false)) {
        CameraConfigurationUtils.setInvertColor(parameters);
      }

      if (!prefs.getBoolean(PreferencesActivity.KEY_DISABLE_BARCODE_SCENE_MODE, true)) {
        CameraConfigurationUtils.setBarcodeSceneMode(parameters);
      }

      if (!prefs.getBoolean(PreferencesActivity.KEY_DISABLE_METERING, true)) {
        CameraConfigurationUtils.setVideoStabilization(parameters);
        CameraConfigurationUtils.setFocusArea(parameters);
        CameraConfigurationUtils.setMetering(parameters);
      }

    }

    parameters.setPreviewSize(bestPreviewSize.x, bestPreviewSize.y);

    theCamera.setParameters(parameters);

    theCamera.setDisplayOrientation(cwRotationFromDisplayToCamera);

    Camera.Parameters afterParameters = theCamera.getParameters();
    Camera.Size afterSize = afterParameters.getPreviewSize();
    if (afterSize != null && (bestPreviewSize.x != afterSize.width || bestPreviewSize.y != afterSize.height)) {
      Log.w(TAG, "Camera said it supported preview size " + bestPreviewSize.x + 'x' + bestPreviewSize.y +
          ", but after setting it, preview size is " + afterSize.width + 'x' + afterSize.height);
      bestPreviewSize.x = afterSize.width;
      bestPreviewSize.y = afterSize.height;
    }
  }
项目:droidxing    文件:CameraConfigurationManager.java   
void setDesiredCameraParameters(Camera camera, boolean safeMode) {
    Camera.Parameters parameters = camera.getParameters();
    Log.i(TAG, "Initial camera parameters: " + parameters.flatten());

    if (safeMode) {
        Log.w(TAG, "In camera config safe mode -- most settings will not be honored");
    }

    initializeTorch(parameters, safeMode);

    CameraConfigurationUtils.setFocus(
            parameters,
            CapturePreferences.getBoolean(CapturePreferences.KEY_AUTO_FOCUS),
            CapturePreferences.getBoolean(CapturePreferences.KEY_DISABLE_CONTINUOUS_FOCUS),
            safeMode);

    if (!safeMode) {
        if (CapturePreferences.getBoolean(CapturePreferences.KEY_INVERT_SCAN)) {
            CameraConfigurationUtils.setInvertColor(parameters);
        }

        if (!CapturePreferences.getBoolean(CapturePreferences.KEY_DISABLE_BARCODE_SCENE_MODE)) {
            CameraConfigurationUtils.setBarcodeSceneMode(parameters);
        }

        if (!CapturePreferences.getBoolean(CapturePreferences.KEY_DISABLE_METERING)) {
            CameraConfigurationUtils.setVideoStabilization(parameters);
            CameraConfigurationUtils.setFocusArea(parameters);
            CameraConfigurationUtils.setMetering(parameters);
        }

    }

    parameters.setPreviewSize(cameraResolution.x, cameraResolution.y);
    camera.setParameters(parameters);

    Camera.Parameters afterParameters = camera.getParameters();
    Camera.Size afterSize = afterParameters.getPreviewSize();
    if (afterSize != null && (cameraResolution.x != afterSize.width || cameraResolution.y != afterSize.height)) {
        Log.w(TAG,
                "Camera said it supported preview size " + cameraResolution.x + 'x' + cameraResolution.y +
                        ", but after setting it, preview size is " + afterSize.width + 'x' + afterSize.height
        );
        cameraResolution.x = afterSize.width;
        cameraResolution.y = afterSize.height;
    }
}
项目:droidxing    文件:CameraConfigurationManager.java   
private void doSetTorch(Camera.Parameters parameters, boolean newSetting, boolean safeMode) {
    CameraConfigurationUtils.setTorch(parameters, newSetting);
    if (!safeMode && !CapturePreferences.getBoolean(CapturePreferences.KEY_DISABLE_EXPOSURE)) {
        CameraConfigurationUtils.setBestExposure(parameters, newSetting);
    }
}