【发布时间】: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作为实例。