1

i'm using ZXing 3.1.0 and i want to rotate camera library to scan, after reading this topic and this

I attempted to paste camera.setDisplayOrientation(90); in setDesiredCameraParameters method for rotate camera but i get this error

Error:(77, 11) java: cannot find symbol
  symbol:   method setDisplayOrientation(int)
  location: variable camera of type android.hardware.Camera

setDesiredCameraParameters method is now:

  void setDesiredCameraParameters(Camera camera) {
    Camera.Parameters parameters = camera.getParameters();
    parameters.set("orientation", "portrait");
    camera.setDisplayOrientation(90);
    if (parameters == null) {
      Log.w(TAG, "Device error: no camera parameters are available. Proceeding without configuration.");
      return;
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    initializeTorch(parameters, prefs);
    String focusMode = findSettableValue(parameters.getSupportedFocusModes(),
                                         Camera.Parameters.FOCUS_MODE_AUTO,
                                         Camera.Parameters.FOCUS_MODE_MACRO);
    if (focusMode != null) {
      parameters.setFocusMode(focusMode);
    }

    parameters.setPreviewSize(cameraResolution.x, cameraResolution.y);
    camera.setParameters(parameters);
  }
Community
  • 1
  • 1
DolDurma
  • 15,753
  • 51
  • 198
  • 377

1 Answers1

1

You can refer to this topic, and place camera.setDisplayOrientation(90); before camera.setParameters(parameters);

void setDesiredCameraParameters(Camera camera) {
Camera.Parameters parameters = camera.getParameters();
parameters.set("orientation", "portrait");
if (parameters == null) {
  Log.w(TAG, "Device error: no camera parameters are available. Proceeding without configuration.");
  return;
}

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

initializeTorch(parameters, prefs);
String focusMode = findSettableValue(parameters.getSupportedFocusModes(),
                                     Camera.Parameters.FOCUS_MODE_AUTO,
                                     Camera.Parameters.FOCUS_MODE_MACRO);
if (focusMode != null) {
  parameters.setFocusMode(focusMode);
}

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

}

Community
  • 1
  • 1
Brandon Yang
  • 2,380
  • 1
  • 15
  • 6