gpt4 book ai didi

android - ZXing 使用 IntentIntegrator 启动 BarcodeScanner 纵向布局

转载 作者:太空狗 更新时间:2023-10-29 13:36:24 24 4
gpt4 key购买 nike

我想以纵向布局启动 BarcodeScanner(因为我的整个应用程序都是纵向布局)。我也想知道,是否可以从 Google Play 一次安装两个应用程序(您在 list 文件中向 Barcode Scanner 添加某种依赖项——我在我的应用程序中使用它——Google Play 会自动在我的应用程序旁边安装 Barcode Scanner) .

谢谢。

最佳答案

如果您需要在纵向模式下扫描条形码,我建议您将 ZXing 库合并到您的应用程序中并进行适当的更改以使其在纵向模式下工作。

在这里获取源代码:zxing

您正在寻找库中的 Android 示例代码以及 core.jar 文件以进行条码扫描。

有关如何使其在 Portrait 中工作的说明,请按照以下说明操作:Issue 178 - zxing - Running ZXing in Portrait

我强烈建议阅读线程以获取有关更改的背景信息,但这是它的基础知识:

  1. In order to make screen work in portrait, set portrait orientation for the activity (e.g. in manifest) and then config the camera: Use camera.setDisplayOrientation(90) in CameraConfigurationManager.setDesiredCameraParameters(Camera camera). But be aware that:

    • setDisplayOrientation(int) requires Android 2.2
    • setDisplayOrientation(int) does not affect the order of byte array passed in PreviewCallback.onPreviewFrame. (Refer to JavaDoc for additional info)
  2. Because preview frames are always in "landscape", we need to rotate them. I used clockwise rotation offered by comment #c11. Do not forget to swap width and height parameters after rotation. DecodeHandler.java, rotate data before buildLuminanceSource in decode(byte[] data, int width, int height)

    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; // Here we are swapping, that's the difference to #11
    width = height;
    height = tmp;
  3. I also modified CameraManager.java, getFramingRectInPreview(), as recommended by #c11:

    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;

zxing 库很容易适应您的应用程序,使其成为更流畅和集成的用户体验。强烈推荐。

关于android - ZXing 使用 IntentIntegrator 启动 BarcodeScanner 纵向布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10014617/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com