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

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

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

问题

我不明白为什么会出现 StackoverflowError。我试图从图像构建位图以扫描 QR 码。decode() 方法中的 source 是按照标准方式构建的:

  1. if (bitmap != null) {
  2. int[] intArray = new int[bitmap.getWidth() * bitmap.getHeight()];
  3. bitmap.getPixels(intArray, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
  4. return new RGBLuminanceSource(bitmap.getWidth(), bitmap.getHeight(), intArray);
  5. }

然后 decode() 抛出错误:
source: Method threw 'java.lang.StackOverflowError' exception. Cannot evaluate com.google.zxing.RGBLuminanceSource.toString()

  1. private QRCodeMultiReader qrCodeReader;
  2. public void decode(LuminanceSource source, ScannerResultListener resultListener) {
  3. try {
  4. BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
  5. String decodedContent = qrCodeReader.decode(bitmap, hints).getText();
  6. Timber.d("qr code scanner has successfully decoded content: [%s]", decodedContent);
  7. resultListener.onScanningSuccess(decodedContent);
  8. } catch (ReaderException re) {
  9. Timber.d(re.getMessage(), "qr code scanner can not decode code");
  10. resultListener.onScanningFailure();
  11. } finally {
  12. qrCodeReader.reset();
  13. }
  14. }

只有在上传具有较大尺寸(例如 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:

  1. if (bitmap != null) {
  2. int[] intArray = new int[bitmap.getWidth() * bitmap.getHeight()];
  3. bitmap.getPixels(intArray, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
  4. 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()

  1. private QRCodeMultiReader qrCodeReader;
  2. public void decode(LuminanceSource source, ScannerResultListener resultListener) {
  3. try {
  4. BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
  5. String decodedContent = qrCodeReader.decode(bitmap, hints).getText();
  6. Timber.d("qr code scanner has successfully decoded content: [%s]", decodedContent);
  7. resultListener.onScanningSuccess(decodedContent);
  8. } catch (ReaderException re) {
  9. Timber.d(re.getMessage(), "qr code scanner can not decode code");
  10. resultListener.onScanningFailure();
  11. } finally {
  12. qrCodeReader.reset();
  13. }
  14. }

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:

确定