在Android Zxing相机在人像模式人像、相机、模式、Android

2023-09-11 11:39:47 作者:Bad guy(烂好人)

我要显示在人像取向 Zxing 的摄像头。

I want to show portrait orientation on Zxing's camera.

如何才能做到这一点?

推荐答案

下面是它如何工作的。

第1步:添加以下行到的德code(byte []的数据,诠释前旋转数据buildLuminanceSource(..)宽度,高度INT)的

Step 1: Add following lines to rotate data before buildLuminanceSource(..) in decode(byte[] data, int width, int height)

德codeHandler.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);

第2步:修改 getFramingRectIn preVIEW()

Step 2: Modify getFramingRectInPreview().

CameraManager.java

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;

第3步:禁用检查景观模式 initFromCameraParameters(...)

Step 3: Disable the check for Landscape Mode in initFromCameraParameters(...)

CameraConfigurationManager.java

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

第四步:添加下面一行到 setDesiredCameraParameters旋转摄像头(...)

相机拍摄模式新手入门

Step 4: Add following line to rotate camera insetDesiredCameraParameters(...)

CameraConfigurationManager.java

camera.setDisplayOrientation(90);

第五步:不要忘记设置的活动方向为纵向。即:清单