android ZXing 3.1.0 setDisplayOrientation方法不存在

时间:2015-01-29 11:01:45

标签: android android-camera

我正在使用ZXing 3.1.0,我希望在阅读this topicthis后想要旋转相机库进行扫描

我尝试在camera.setDisplayOrientation(90);方法中粘贴setDesiredCameraParameters以旋转相机但我收到此错误

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

setDesiredCameraParameters方法现在是:

  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);
  }

1 个答案:

答案 0 :(得分:1)

您可以参考this topic,并在camera.setDisplayOrientation(90);之前放置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);

}