RBGLuminanceSource.toString在图像尺寸较大时抛出StackOverflowError

huangapple go评论74阅读模式
英文:

RBGLuminanceSource.toString is throwing StackOverflowError when dimensions of image are big

问题

我不明白为什么会出现 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() 抛出错误:
source: Method threw 'java.lang.StackOverflowError' exception. Cannot evaluate 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 像素)的图像时才会出现此问题。当我将上传的图像缩小到高度例如 2160 像素时,一切正常,图像被正确扫描。我找不到有关 zxing 尺寸限制的任何信息。

有人知道是为什么吗?

英文:

I cannot understand why I'm getting StackoverflowError. I'm trying to build bitmap from an image to scan QR code. source from decode() method is build in standard way:

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);

And than decode() throws error:
source: Method threw 'java.lang'StackOverflowError' exception. Cannot evaluate 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();
        }
      }

It happens only when I upload image with big dimensions (e. g. 1242x2688px). When I downsize uploaded image to height for example 2160px, everything is ok., and image is scanned properly.
I cannot find anything about zxing dimensional restrictions.

Does anybody know why is that?

答案1

得分: 0

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

英文:

Problem solved.
I had to upgrade Zxing libs to newer version. In my problem 3.3.1 was sufficient.
But newer libs require SDK 19+.

huangapple
  • 本文由 发表于 2020年10月26日 15:54:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/64533241.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定