我正在使用ZXing 3.1.0,我希望在阅读this topic和this后想要旋转相机库进行扫描
我尝试在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);
}
答案 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);
}