Created
July 16, 2020 04:04
-
-
Save typelogic/07d2d0af263567c0fbf960bf5caca77a to your computer and use it in GitHub Desktop.
QR reader snippet to read binary qr encoded
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.google.zxing.*; | |
| import com.google.zxing.client.j2se.BufferedImageLuminanceSource; | |
| import com.google.zxing.common.HybridBinarizer; | |
| private static byte[] decodeQRCode(File qrCodeimage) throws IOException | |
| { | |
| BufferedImage bufferedImage = ImageIO.read(qrCodeimage); | |
| LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage); | |
| BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); | |
| byte[] content = new byte[0]; | |
| try { | |
| Result result = new MultiFormatReader().decode(bitmap); | |
| Map m = result.getResultMetadata(); | |
| if (m.containsKey(ResultMetadataType.BYTE_SEGMENTS)) { | |
| List L = (List)m.get(ResultMetadataType.BYTE_SEGMENTS); | |
| content = (byte[])L.get(0); | |
| } else { | |
| content = result.getText().getBytes(); | |
| } | |
| } catch (NotFoundException e) { | |
| System.out.println("no QR Code in the image"); | |
| } | |
| return content; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment