zxing 中 Reader 的 reset() - android
reset() of Reader in zxing - android
我在 GitHub 上查看 zxing 存储库已经好几个小时了。 androidtest
的 BenchmarkAsyncTask
遍历文件路径,并在不调用 reader
.
的 reset()
的情况下连续解码一些图像文件
但是Reader.reset的评论里说
Resets any internal state the implementation has after a decode, to prepare it
for reuse.
既然我们重用了multiFormatReader
,难道我们不应该调用reset()
吗?
如果你一步步调试 ZXing 源代码,你会看到 reset() 对除了 RSS14Reader 和 RSSExpandedReader[=26 之外的所有阅读器什么都不做=].
什么都不做:
@Override
public void reset() {
// do nothing
}
RSS14Reader.reset():
@Override
public void reset() {
possibleLeftPairs.clear();
possibleRightPairs.clear();
}
RSSExpandedReader.reset()
@Override
public void reset() {
this.pairs.clear();
this.rows.clear();
}
如果你只是想看二维码,没有区别。例如:
String[] fileNames = new String[]{"qrcode-1.jpg", "qrcode-2.jpg"};
File file = null;
BufferedImage image = null;
RGBLuminanceSource source = null;
BinaryBitmap bitmap = null;
Result result = null;
MultiFormatReader reader = new MultiFormatReader();
try {
for (String fileName : fileNames) {
file = new File(fileName);
image = ImageIO.read(file);
System.out.println(image.getWidth() + ", " + image.getHeight());
int[] pixels = image.getRGB(0, 0, image.getWidth(), image.getHeight(), null, 0, image.getWidth());
source = new RGBLuminanceSource(image.getWidth(), image.getHeight(), pixels);
bitmap = new BinaryBitmap(new HybridBinarizer(source));
result = reader.decode(bitmap);
System.out.println(result.getText());
//reader.reset();
}
}
catch (Exception exception) {
System.out.println(exception);
}
我在 GitHub 上查看 zxing 存储库已经好几个小时了。 androidtest
的 BenchmarkAsyncTask
遍历文件路径,并在不调用 reader
.
reset()
的情况下连续解码一些图像文件
但是Reader.reset的评论里说
Resets any internal state the implementation has after a decode, to prepare it for reuse.
既然我们重用了multiFormatReader
,难道我们不应该调用reset()
吗?
如果你一步步调试 ZXing 源代码,你会看到 reset() 对除了 RSS14Reader 和 RSSExpandedReader[=26 之外的所有阅读器什么都不做=].
什么都不做:
@Override
public void reset() {
// do nothing
}
RSS14Reader.reset():
@Override
public void reset() {
possibleLeftPairs.clear();
possibleRightPairs.clear();
}
RSSExpandedReader.reset()
@Override
public void reset() {
this.pairs.clear();
this.rows.clear();
}
如果你只是想看二维码,没有区别。例如:
String[] fileNames = new String[]{"qrcode-1.jpg", "qrcode-2.jpg"};
File file = null;
BufferedImage image = null;
RGBLuminanceSource source = null;
BinaryBitmap bitmap = null;
Result result = null;
MultiFormatReader reader = new MultiFormatReader();
try {
for (String fileName : fileNames) {
file = new File(fileName);
image = ImageIO.read(file);
System.out.println(image.getWidth() + ", " + image.getHeight());
int[] pixels = image.getRGB(0, 0, image.getWidth(), image.getHeight(), null, 0, image.getWidth());
source = new RGBLuminanceSource(image.getWidth(), image.getHeight(), pixels);
bitmap = new BinaryBitmap(new HybridBinarizer(source));
result = reader.decode(bitmap);
System.out.println(result.getText());
//reader.reset();
}
}
catch (Exception exception) {
System.out.println(exception);
}