【问题标题】:Zxing (v3.2.0) Camera fixed portrait mode using eclipseZxing (v3.2.0) 使用eclipse的相机固定人像模式
【发布时间】:2016-05-23 11:51:57
【问题描述】:

我按照Zxing Camera in Portrait mode on Android的指示一步一步地在用户使用zxing相机时显示人像。

但这行不通。扫描仪仍以横向模式出现。 我认为这是因为我使用的是 Zxing 的最新版本 (v3.2.0) 并且该指令已被弃用。

如何在 v3.2.0 Zxing 中做到这一点?


无论如何,以下是我尝试过的步骤:

  1. 修改 buildLuminanceSource(..) DecodeHandler.java

代码:

byte[] rotatedData = new byte[data.length];
for (int y = 0; y < height; y++) {
    for (int x = 0; x < width; x++)
         rotatedData[x * height + height - y - 1] = data[x + y * width];
}
int tmp = width;
width = height;
height = tmp;

PlanarYUVLuminanceSource source = activity.getCameraManager().buildLuminanceSource(rotatedData, width, height);

  1. 在CameraManager.java中修改getFramingRectInPreview()

代码:

rect.left = rect.left * cameraResolution.y / screenResolution.x;
rect.right = rect.right * cameraResolution.y / screenResolution.x;
rect.top = rect.top * cameraResolution.x / screenResolution.y;
rect.bottom = rect.bottom * cameraResolution.x / screenResolution.y;

  1. 在 CameraConfigurationManager.java 中修改 initFromCameraParameters(...)

    在Zxing(v3.2.0)中,没有找到如下代码

代码:

//remove the following
if (width < height) {
Log.i(TAG, "Display reports portrait orientation; assuming this is incorrect");
int temp = width;
width = height;
height = temp;
}

  1. 在 CameraConfigurationManager.java 的 setDesiredCameraParameters(...) 中添加以下行以旋转相机

代码:

camera.setDisplayOrientation(90);

  1. 在我的项目中,修改AndroidManifest.xml

代码:

android:screenOrientation="portrait"

【问题讨论】:

    标签: android eclipse zxing landscape-portrait portrait


    【解决方案1】:

    经过几天的反复试验,这是我的工作解决方案:

    它需要额外的工作,比方说第 6 步。无论如何,始终设置纵向方向。它奏效了。


    第 6 步。 在CaptureActivity.java

    中修改onResume
    if (prefs.getBoolean(PreferencesActivity.KEY_DISABLE_AUTO_ORIENTATION, true)) {
      //setRequestedOrientation(getCurrentOrientation()); // mark this line
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    } else {
      //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);  // mark this line
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多