【问题标题】:RBGLuminanceSource.toString is throwing StackOverflowError when dimensions of image are big当图像尺寸很大时,RBGLuminanceSource.toString 会抛出 StackOverflowError
【发布时间】:2020-11-09 04:35:58
【问题描述】:

我不明白为什么会收到 StackoverflowError。我正在尝试从图像构建位图以扫描 QR 码。 decode() 方法中的 source 以标准方式构建:

if (bitmap != null) {
      int[] intArray = new int[bitmap.getWidth() * bitmap.getHeight()];
      bitmap.getPixels(intArray, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
      return new RGBLuminanceSource(bitmap.getWidth(), bitmap.getHeight(), intArray);

然后 decode() 抛出错误: 来源:方法引发了“java.lang'StackOverflowError”异常。无法评估 com.google.zxing.RGBLuminanceSource.toString()

private QRCodeMultiReader qrCodeReader;
      
public void decode(LuminanceSource source, ScannerResultListener resultListener) {
        try {
          BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
          String decodedContent = qrCodeReader.decode(bitmap, hints).getText();
          Timber.d("qr code scanner has successfully decoded content: [%s]", decodedContent);
          resultListener.onScanningSuccess(decodedContent);
        } catch (ReaderException re) {
          Timber.d(re.getMessage(), "qr code scanner can not decode code");
          resultListener.onScanningFailure();
        } finally {
          qrCodeReader.reset();
        }
      }

仅当我上传大尺寸的图片(例如 1242x2688 像素)时才会发生这种情况。当我将上传的图像缩小到例如 2160px 的高度时,一切正常,并且图像被正确扫描。 我找不到任何关于 zxing 尺寸限制的信息。

有人知道这是为什么吗?

【问题讨论】:

  • 能否提供完整的堆栈轨迹和decode()的完整代码。 SOE往往是循环调用引起的,方法A调用方法B,方法B调用方法A作为实例。

标签: java qr-code zxing


【解决方案1】:

问题解决了。 我不得不将 Zxing 库升级到更新版本。在我的问题中,3.3.1 就足够了。 但较新的库需要 SDK 19+。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-24
    • 1970-01-01
    相关资源
    最近更新 更多