Android Camera Set setBestExposure(Camera.Parameters parameters, boolean lightOn)

Here you can find the source of setBestExposure(Camera.Parameters parameters, boolean lightOn)

Description

set Best Exposure

License

Apache License

Declaration

public static void setBestExposure(Camera.Parameters parameters,
            boolean lightOn) 

Method Source Code

//package com.java2s;
/*/* w  w w  . java2s .  c o m*/
 * Copyright (C) 2014 ZXing authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import android.hardware.Camera;

import android.util.Log;

public class Main {
    private static final String TAG = "CameraConfiguration";
    private static final float MAX_EXPOSURE_COMPENSATION = 1.5f;
    private static final float MIN_EXPOSURE_COMPENSATION = 0.0f;

    public static void setBestExposure(Camera.Parameters parameters,
            boolean lightOn) {
        int minExposure = parameters.getMinExposureCompensation();
        int maxExposure = parameters.getMaxExposureCompensation();
        float step = parameters.getExposureCompensationStep();
        if ((minExposure != 0 || maxExposure != 0) && step > 0.0f) {
            // Set low when light is on
            float targetCompensation = lightOn ? MIN_EXPOSURE_COMPENSATION
                    : MAX_EXPOSURE_COMPENSATION;
            int compensationSteps = Math.round(targetCompensation / step);
            float actualCompensation = step * compensationSteps;
            // Clamp value:
            compensationSteps = Math.max(
                    Math.min(compensationSteps, maxExposure), minExposure);
            if (parameters.getExposureCompensation() == compensationSteps) {
                Log.i(TAG, "Exposure compensation already set to "
                        + compensationSteps + " / " + actualCompensation);
            } else {
                Log.i(TAG, "Setting exposure compensation to "
                        + compensationSteps + " / " + actualCompensation);
                parameters.setExposureCompensation(compensationSteps);
            }
        } else {
            Log.i(TAG, "Camera does not support exposure compensation");
        }
    }
}

Related

  1. setBarcodeSceneMode(Camera.Parameters parameters)
  2. setBestPreviewFPS(Camera.Parameters parameters)
  3. setBestPreviewFPS(Camera.Parameters parameters, int minFPS, int maxFPS)
  4. setCameraDisplayOrientation(Context mContext, int cameraId, Camera camera)
  5. setFocus(Camera.Parameters parameters, boolean autoFocus, boolean disableContinuous, boolean safeMode)