Java Code Examples for android.hardware.Camera#Parameters

The following examples show how to use android.hardware.Camera#Parameters . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CameraSource.java    From android-vision with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the flash mode.
 *
 * @param mode flash mode.
 * @return {@code true} if the flash mode is set, {@code false} otherwise
 * @see #getFlashMode()
 */
public boolean setFlashMode(@FlashMode String mode) {
    synchronized (cameraLock) {
        if (camera != null && mode != null) {
            Camera.Parameters parameters = camera.getParameters();
            if (parameters.getSupportedFlashModes().contains(mode)) {
                parameters.setFlashMode(mode);
                camera.setParameters(parameters);
                flashMode = mode;
                return true;
            }
        }

        return false;
    }
}
 
Example 2
Source File: CameraPreview.java    From cordova-plugin-camera-preview with MIT License 6 votes vote down vote up
private boolean getSupportedColorEffects(CallbackContext callbackContext) {
  if(this.hasCamera(callbackContext) == false){
    return true;
  }

  Camera camera = fragment.getCamera();
  Camera.Parameters params = camera.getParameters();
  List<String> supportedColors;
  supportedColors = params.getSupportedColorEffects();
  JSONArray jsonColorEffects = new JSONArray();

  if (supportedColors != null) {
    for (int i=0; i<supportedColors.size(); i++) {
        jsonColorEffects.put(new String(supportedColors.get(i)));
    }
  }

  callbackContext.success(jsonColorEffects);

  return true;
}
 
Example 3
Source File: CameraConfigurationUtils.java    From FoodOrdering with Apache License 2.0 6 votes vote down vote up
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");
	}
}
 
Example 4
Source File: CameraPreview.java    From cordova-plugin-camera-preview with MIT License 6 votes vote down vote up
private boolean setFlashMode(String flashMode, CallbackContext callbackContext) {
  if(this.hasCamera(callbackContext) == false){
    return true;
  }

  Camera camera = fragment.getCamera();
  Camera.Parameters params = camera.getParameters();

  List<String> supportedFlashModes;
  supportedFlashModes = camera.getParameters().getSupportedFlashModes();
  if (supportedFlashModes.indexOf(flashMode) > -1) {
    params.setFlashMode(flashMode);
  } else {
    callbackContext.error("Flash mode not recognised: " + flashMode);
    return true;
  }

  fragment.setCameraParameters(params);

  callbackContext.success(flashMode);
  return true;
}
 
Example 5
Source File: CameraPreview.java    From cordova-plugin-camera-preview with MIT License 6 votes vote down vote up
private boolean getExposureCompensation(CallbackContext callbackContext) {
  if(this.hasCamera(callbackContext) == false){
    return true;
  }

  Camera camera = fragment.getCamera();
  Camera.Parameters params = camera.getParameters();

  if (camera.getParameters().getMinExposureCompensation() == 0 && camera.getParameters().getMaxExposureCompensation() == 0) {
    callbackContext.error("Exposure corection not supported");
  } else {
    int exposureCompensation = camera.getParameters().getExposureCompensation();
    callbackContext.success(exposureCompensation);
  }

  return true;
}
 
Example 6
Source File: CameraSource.java    From Bluefruit_LE_Connect_Android_V2 with MIT License 6 votes vote down vote up
/**
 * Sets the flash mode.
 *
 * @param mode flash mode.
 * @return {@code true} if the flash mode is set, {@code false} otherwise
 * @see #getFlashMode()
 */
public boolean setFlashMode(@FlashMode String mode) {
    synchronized (mCameraLock) {
        if (mCamera != null && mode != null) {
            Camera.Parameters parameters = mCamera.getParameters();
            if (parameters.getSupportedFlashModes().contains(mode)) {
                parameters.setFlashMode(mode);
                mCamera.setParameters(parameters);
                mFlashMode = mode;
                return true;
            }
        }

        return false;
    }
}
 
Example 7
Source File: CameraSource.java    From android-vision with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the flash mode.
 *
 * @param mode flash mode.
 * @return {@code true} if the flash mode is set, {@code false} otherwise
 * @see #getFlashMode()
 */
public boolean setFlashMode(@FlashMode String mode) {
    synchronized (cameraLock) {
        if (camera != null && mode != null) {
            Camera.Parameters parameters = camera.getParameters();
            if (parameters.getSupportedFlashModes().contains(mode)) {
                parameters.setFlashMode(mode);
                camera.setParameters(parameters);
                flashMode = mode;
                return true;
            }
        }

        return false;
    }
}
 
Example 8
Source File: Camera1Manager.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private void turnVideoCameraFeaturesOn(Camera camera, Camera.Parameters parameters) {
    if (parameters.getSupportedFocusModes().contains(
            Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
        parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
    }
    camera.setParameters(parameters);
}
 
Example 9
Source File: CameraConfigurationManager.java    From BarcodeEye with Apache License 2.0 5 votes vote down vote up
/**
 * See http://stackoverflow.com/a/19434459/552902
 *
 * @param mCamera
 */
public static void googleGlassXE10WorkAround(Camera camera) {
    Camera.Parameters params = camera.getParameters();
    params.setPreviewFpsRange(30000, 30000);
    params.setPreviewSize(640, 360);
    //        if (params.isZoomSupported()) {
    //            Log.v("@@@@@@@@@", "zoom is supported!");
    //            Log.v("@@@@@@@@@", "zoom max: " + params.getMaxZoom());
    //            params.setZoom(10);
    //        } else {
    //            Log.w("@@@@@@@@@", "zoom is NOT supported!");
    //        }
    camera.setParameters(params);
}
 
Example 10
Source File: VideoRecordSurface.java    From VideoRecord with Apache License 2.0 5 votes vote down vote up
private void initParameters() {
    CamcorderProfile mProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_1080P);
    Camera.Parameters mParams = mCamera.getParameters();
    mParams.setPreviewSize(mProfile.videoFrameWidth, mProfile.videoFrameHeight);
    size = mParams.getPreviewSize();
    List<String> focusModes = mParams.getSupportedFocusModes();
    if (focusModes.contains("continuous-video")) {
        mParams.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
    }
    mCamera.setParameters(mParams);
}
 
Example 11
Source File: CameraConfigurationUtils.java    From ZXing-Standalone-library with Apache License 2.0 5 votes vote down vote up
public static void setFocus(Camera.Parameters parameters,
                            boolean autoFocus,
                            boolean disableContinuous,
                            boolean safeMode) {
  List<String> supportedFocusModes = parameters.getSupportedFocusModes();
  String focusMode = null;
  if (autoFocus) {
    if (safeMode || disableContinuous) {
      focusMode = findSettableValue("focus mode",
                                     supportedFocusModes,
                                     Camera.Parameters.FOCUS_MODE_AUTO);
    } else {
      focusMode = findSettableValue("focus mode",
                                    supportedFocusModes,
                                    Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE,
                                    Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO,
                                    Camera.Parameters.FOCUS_MODE_AUTO);
    }
  }
  // Maybe selected auto-focus but not available, so fall through here:
  if (!safeMode && focusMode == null) {
    focusMode = findSettableValue("focus mode",
                                  supportedFocusModes,
                                  Camera.Parameters.FOCUS_MODE_MACRO,
                                  Camera.Parameters.FOCUS_MODE_EDOF);
  }
  if (focusMode != null) {
    if (focusMode.equals(parameters.getFocusMode())) {
      Log.i(TAG, "Focus mode already set to " + focusMode);
    } else {
      parameters.setFocusMode(focusMode);
    }
  }
}
 
Example 12
Source File: Camera1ApiManager.java    From rtmp-rtsp-stream-client-java with Apache License 2.0 5 votes vote down vote up
/**
 * @required: <uses-permission android:name="android.permission.FLASHLIGHT"/>
 */
public void disableLantern() {
  if (camera != null) {
    Camera.Parameters parameters = camera.getParameters();
    parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
    camera.setParameters(parameters);
    lanternEnable = false;
  }
}
 
Example 13
Source File: CameraHelper.java    From RecordVideo with Apache License 2.0 5 votes vote down vote up
/**
 * 设置相机对焦模式
 *
 * @param focusMode
 * @param camera
 */
public static void setCameraFocusMode(String focusMode, Camera camera) {
    Camera.Parameters parameters = camera.getParameters();
    List<String> sfm = parameters.getSupportedFocusModes();
    if (sfm.contains(focusMode)) {
        parameters.setFocusMode(focusMode);
    }
    camera.setParameters(parameters);
}
 
Example 14
Source File: CameraConfigurationManager.java    From vinci with Apache License 2.0 5 votes vote down vote up
private void setFlash(Camera.Parameters parameters) {
    // FIXME: This is a hack to turn the flash off on the Samsung Galaxy.
    // And this is a hack-hack to work around a different value on the Behold II
    // Restrict Behold II check to Cupcake, per Samsung's advice
    //if (Build.MODEL.contains("Behold II") &&
    //    CameraManager.SDK_INT == Build.VERSION_CODES.CUPCAKE) {
    if (Build.MODEL.contains("Behold II") && CameraManager.SDK_INT == 3) { // 3 = Cupcake
        parameters.set("flash-value", 1);
    } else {
        parameters.set("flash-value", 2);
    }
    // This is the standard setting to turn the flash off that all devices should honor.
    parameters.set("flash-mode", "off");
}
 
Example 15
Source File: CameraInterface.java    From imsdk-android with MIT License 5 votes vote down vote up
public void setFlashMode(String flashMode) {
    if (mCamera == null)
        return;
    Camera.Parameters params = mCamera.getParameters();
    params.setFlashMode(flashMode);
    mCamera.setParameters(params);
}
 
Example 16
Source File: CameraConfigurationManager.java    From lunzi with Apache License 2.0 5 votes vote down vote up
private void setFlash(Camera.Parameters parameters) {
    // FIXME: This is a hack to turn the flash off on the Samsung Galaxy.
    // And this is a hack-hack to work around a different value on the Behold II
    // Restrict Behold II check to Cupcake, per Samsung's advice
    //if (Build.MODEL.contains("Behold II") &&
    //    CameraManager.SDK_INT == Build.VERSION_CODES.CUPCAKE) {
    if (Build.MODEL.contains("Behold II") && CameraManager.SDK_INT == 3) { // 3 = Cupcake
        parameters.set("flash-value", 1);
    } else {
        parameters.set("flash-value", 2);
    }
    // This is the standard setting to turn the flash off that all devices should honor.
    parameters.set("flash-mode", "off");
}
 
Example 17
Source File: CameraHelper.java    From OkCamera with Apache License 2.0 5 votes vote down vote up
public List<Camera.Size> getPreviewSizes() {
    if(mCamera == null)
        return null;
    Camera.Parameters param = mCamera.getParameters();
    if(param != null) {
        return param.getSupportedPreviewSizes();
    }
    return  null;
}
 
Example 18
Source File: CameraActivity.java    From Android-MobileFaceNet-MTCNN-FaceAntiSpoofing with MIT License 5 votes vote down vote up
/**
 * 打开相机
 * @param holder SurfaceHolder
 */
private void openCamera(SurfaceHolder holder) {
    releaseCamera();
    mCamera = Camera.open(CAMERA_ID);
    Camera.Parameters parameters = mCamera.getParameters();
    displayDegree = setCameraDisplayOrientation(CAMERA_ID, mCamera);

    // 获取合适的分辨率
    mSize = getOptimalSize(parameters.getSupportedPreviewSizes(), mSurfaceView.getWidth(), mSurfaceView.getHeight());
    parameters.setPreviewSize(mSize.width, mSize.height);

    parameters.setPreviewFormat(IMAGE_FORMAT);
    mCamera.setParameters(parameters);

    try {
        mCamera.setPreviewDisplay(holder);
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }

    // 相机每一帧图像回调
    mCamera.setPreviewCallback(new Camera.PreviewCallback() {
        @Override
        public void onPreviewFrame(byte[] data, Camera camera) {
            mData = data;
            camera.addCallbackBuffer(data);
        }
    });

    mCamera.startPreview();
}
 
Example 19
Source File: CameraConfigurationManager.java    From reacteu-app with MIT License 4 votes vote down vote up
private void initializeTorch(Camera.Parameters parameters, SharedPreferences prefs, boolean safeMode) {
  boolean currentSetting = prefs.getBoolean(PreferencesActivity.KEY_FRONT_LIGHT, false);
  doSetTorch(parameters, currentSetting, safeMode);
}
 
Example 20
Source File: CameraSource.java    From android-vision with Apache License 2.0 4 votes vote down vote up
/**
 * Calculates the correct rotation for the given camera id and sets the rotation in the
 * parameters.  It also sets the camera's display orientation and rotation.
 *
 * @param parameters the camera parameters for which to set the rotation
 * @param cameraId   the camera id to set rotation based on
 */
private void setRotation(Camera camera, Camera.Parameters parameters, int cameraId) {
    WindowManager windowManager =
            (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    int degrees = 0;
    int rotation = windowManager.getDefaultDisplay().getRotation();
    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;
        default:
            Log.e(TAG, "Bad rotation value: " + rotation);
    }

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

    int angle;
    int displayAngle;
    if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        angle = (cameraInfo.orientation + degrees) % 360;
        displayAngle = (360 - angle) % 360; // compensate for it being mirrored
    } else {  // back-facing
        angle = (cameraInfo.orientation - degrees + 360) % 360;
        displayAngle = angle;
    }

    // This corresponds to the rotation constants in {@link Frame}.
    mRotation = angle / 90;

    camera.setDisplayOrientation(displayAngle);
    parameters.setRotation(angle);
}