Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Decode an image based either on a full path or base64 content
private static String decodeQRCode(Object qrCodeImage) {
Result result = null;
try {
BufferedImage bufferedImage;
// if not (probably it is a URL
if (((String) qrCodeImage).contains("http")) {
bufferedImage = URL((String)qrCodeImage)));
// if is a Base64 String
} else {
byte[] decoded = Base64.decodeBase64((String)qrCodeImage);
bufferedImage = ByteArrayInputStream(decoded));
LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
result = new MultiFormatReader().decode(bitmap);
} catch (NotFoundException | IOException e) {
log.error("Error reading the QR Code", e);
return result.getText();
Copy link

eliasnogueira commented Feb 11, 2021

The full code example can be found at

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