【问题标题】:android + ZXing barcode scanning library - custom size & orientation [duplicate]android + ZXing条码扫描库-自定义大小和方向[重复]
【发布时间】:2013-04-27 22:48:23
【问题描述】:

我已经成功使用了 ZXing 条码扫描库,但仅限横向模式。

我还成功地将相机预览设置为纵向模式并正确显示(不拉伸),但现在条形码根本不起作用。 这是我对“CameraConfigurationManager.java”上的“setDesiredCameraParameters”所做的更改,以便正确显示相机:

void setDesiredCameraParameters(Camera camera)
{
    Camera.Parameters parameters = camera.getParameters();
    Log.d(TAG, "Setting preview size: " + cameraResolution);
    setFlash(parameters);
    setZoom(parameters);
    camera.setDisplayOrientation(90);
    parameters.set("rotation", 90);
    parameters.setPreviewSize(cameraResolution.y, cameraResolution.x);
    camera.setParameters(parameters);
}

我尝试了其他地方提到的一些解决方案,但它们要么不起作用,要么起作用但无法正确显示相机预览。 例子: How to use Zxing in portrait mode? http://code.google.com/p/zxing/issues/detail?id=178#c46 https://github.com/pplante/zxing-android/issues

完成后,我还需要自定义矩形的位置和大小以进行扫描。我知道我需要更改“CameraManager.java”上的“setManualFramingRect”,但我不确定我是否正确。这是代码:

public void setManualFramingRect(Rect rect)
{
    if (initialized)
    {
        Point screenResolution = configManager.getScreenResolution();
        if (rect.right >= screenResolution.x)
            rect.right = screenResolution.x - 1;
        if (rect.left < 0)
            rect.left = 0;
        if (rect.bottom >= screenResolution.y)
            rect.bottom = screenResolution.y - 1;
        if (rect.top < 0)
            rect.top = 0;
        framingRect = rect;
        Log.d(TAG, "Calculated manual framing rect: " + framingRect);
        framingRectInPreview = null;
    }
    else
        _requestedFramingRect = new Rect(rect);
}

当然,我已经将“openDriver”改为调用:

if (_requestedFramingRect != null)
    setManualFramingRect(_requestedFramingRect);

请帮帮我。


编辑:现在我发现它在某些设备上不起作用。一开始就崩溃了,如果你调试的话,你可以看到即使预览也不能正常工作。

【问题讨论】:

标签: android barcode zxing portrait


【解决方案1】:

除此之外还有更多。例如,当相机方向与设备方向不同时,您需要实际“旋转”相机数据(或者,将其扫描为垂直)。而且在使用前置摄像头时,您需要考虑到它的旋转是反向的。

【讨论】:

  • 我尝试了我已经写过的链接 - 它不起作用。你知道有人成功做到了吗?
  • 好吧,我的意思是如果有人可以分享这个问题的解决方案(免费)。 :)
  • 无论如何,我不明白为什么我需要旋转输入图像,因为无论方向如何都可以读取二维码。
  • 是的,二维码可以任意旋转。如果您是水平扫描,则不是 1D。
猜你喜欢
  • 2020-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-09
  • 2018-08-16
  • 2012-04-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多