Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String readQRCode2(String fileName) {
- File file = new File(fileName);
- BufferedImage image = null;
- BinaryBitmap bitmap = null;
- Result result = null;
- try {
- image = ImageIO.read(file);
- int[] pixels = image.getRGB(0, 0, image.getWidth(), image.getHeight(), null, 0, image.getWidth());
- RGBLuminanceSource source = new RGBLuminanceSource(image.getWidth(), image.getHeight(), pixels);
- bitmap = new BinaryBitmap(new HybridBinarizer(source));
- } catch (IOException e) {
- e.printStackTrace();
- }
- if (bitmap == null) {
- return null;
- }
- QRCodeReader reader = new QRCodeReader();
- try {
- Map<DecodeHintType, Object> hintMap = new Hashtable<DecodeHintType, Object>();
- hintMap.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
- hintMap.put(DecodeHintType.POSSIBLE_FORMATS, EnumSet.allOf(BarcodeFormat.class));
- result = reader.decode(bitmap, hintMap);
- log.info("Decoded image successfully, result was : '" + result.getText() + "'");
- return result.getText();
- } catch (NotFoundException e) {
- e.printStackTrace();
- } catch (ChecksumException e) {
- e.printStackTrace();
- } catch (FormatException e) {
- e.printStackTrace();
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement