Skip to content

Instantly share code, notes, and snippets.

@GaetanoPiazzolla
Last active October 27, 2021 20:40
Show Gist options
  • Save GaetanoPiazzolla/864e7471ea33788bca898fa8e0179b8b to your computer and use it in GitHub Desktop.
Save GaetanoPiazzolla/864e7471ea33788bca898fa8e0179b8b to your computer and use it in GitHub Desktop.
// 1 - read text from file
File file = new File("C://temp/green-pass.jpg");
BufferedImage bufferedImage = ImageIO.read(file);
LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Result result = new MultiFormatReader().decode(bitmap);
String text = result.getText();
// 2 - remove prefix "HC1:" and decode base45 string
byte[] bytecompressed = Base45.getDecoder().decode(text.substring(4));
// 3 - inflate string using zlib
Inflater inflater = new Inflater();
inflater.setInput(bytecompressed);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(bytecompressed.length);
byte[] buffer = new byte[BUFFER_SIZE];
while (!inflater.finished()) {
final int count = inflater.inflate(buffer);
outputStream.write(buffer, 0, count);
}
@GaetanoPiazzolla
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment