I'm looking the zxing repository at GitHub for hours. The BenchmarkAsyncTask
of androidtest
walk throught a file path and continuously decode some image files wihout call reset()
of the reader
.
But in the comment of Reader.reset, it says that
Resets any internal state the implementation has after a decode, to prepare it for reuse.
Since we reused the multiFormatReader
, should do not we call the reset()
?
If you debug the ZXing source code step by step, you will see that reset() does nothing for all readers except RSS14Reader and RSSExpandedReader.
Do nothing:
@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();
}
If you just want to read QR code, there's no difference. For example:
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);
}