简体   繁体   English

Zxing(v3.2.0)使用Eclipse的相机固定人像模式

[英]Zxing (v3.2.0) Camera fixed portrait mode using eclipse

I follow the instruction step by step on Zxing Camera in Portrait mode on Android to display portrait while user's using zxing camera. 在Android的人像模式下按照Zxing Camera的说明逐步操作,以在用户使用zxing相机时显示人像。

But it won't work. 但这是行不通的。 The scanner is still appeared in the landscape mode. 扫描仪仍以横向模式出现。 I think it's because i am using the latest version (v3.2.0) of Zxing and the instruction is deprecated. 我认为这是因为我使用的是Zxing的最新版本(v3.2.0) ,并且该指令已弃用。

How can this be done in v3.2.0 Zxing? Zxing v3.2.0中该如何完成?


Anyway, Here are the steps I've tried: 无论如何,这是我尝试的步骤:

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

Code: 码:

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. Modify getFramingRectInPreview() in CameraManager.java 在CameraManager.java中修改getFramingRectInPreview()

Code: 码:

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. Modify initFromCameraParameters(...) in CameraConfigurationManager.java 在CameraConfigurationManager.java中修改initFromCameraParameters(...)

    In Zxing (v3.2.0), I don't find the following code 在Zxing(v3.2.0)中,我找不到以下代码

Code: 码:

//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. Add following line to rotate camera in setDesiredCameraParameters(...) in CameraConfigurationManager.java 在CameraConfigurationManager.java中的setDesiredCameraParameters(...)中添加以下行以旋转摄像机

Code: 码:

camera.setDisplayOrientation(90);

  1. In my project, modify AndroidManifest.xml 在我的项目中,修改AndroidManifest.xml

Code: 码:

android:screenOrientation="portrait"

After doing trials and errors for couple days, here's my working solution: 经过几天的反复试验,这是我的工作解决方案:

It needs extra work, let's say Step 6. Always set the portrait orientation no matter what. 它需要额外的工作,比方说第6步。无论如何,始终设置纵向。 And it worked. 而且有效。


Step 6. Modify onResume in CaptureActivity.java 步骤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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM