/** * @param srcImgFilePath * 要解码的图片地址 * @return {Result} */ @SuppressWarnings("finally") public static Result decode(String srcImgFilePath) { Result result = null; BufferedImage image; try { File srcFile = new File(srcImgFilePath); image = ImageIO.read(srcFile); if (null != image) { LuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); Hashtable<DecodeHintType, String> hints = new Hashtable<DecodeHintType, String>(); hints.put(DecodeHintType.CHARACTER_SET, "UTF-8"); result = new MultiFormatReader().decode(bitmap, hints); } else { throw new IllegalArgumentException ("Could not decode image."); } } catch (Exception e) { e.printStackTrace(); } finally { return result; } }
/** * 条形码解码 */ public static String decode(BufferedImage image) { Result result = null; try { if (image == null) { System.out.println("the decode image may be not exit."); } LuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); result = new MultiFormatReader().decode(bitmap, null); return result.getText(); } catch (Exception e) { e.printStackTrace(); } return null; }
/** * 解析二维码 * * @param file 二维码图片 * @return * @throws Exception */ public static String decode(File file) throws Exception { BufferedImage image; image = ImageIO.read(file); if (image == null) { return null; } BufferedImageLuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); Result result; Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>(); hints.put(DecodeHintType.CHARACTER_SET, CHARSET); result = new MultiFormatReader().decode(bitmap, hints); String resultStr = result.getText(); return resultStr; }
public static String decodeQr(String filePath) { String retStr = ""; if ("".equalsIgnoreCase(filePath) && filePath.length() == 0) { return "图片路径为空!"; } try { BufferedImage bufferedImage = ImageIO.read(new FileInputStream(filePath)); LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage); Binarizer binarizer = new HybridBinarizer(source); BinaryBitmap bitmap = new BinaryBitmap(binarizer); HashMap<DecodeHintType, Object> hintTypeObjectHashMap = new HashMap<>(); hintTypeObjectHashMap.put(DecodeHintType.CHARACTER_SET, "UTF-8"); Result result = new MultiFormatReader().decode(bitmap, hintTypeObjectHashMap); retStr = result.getText(); } catch (Exception e) { logger.error("", e); } return retStr; }
public static String decodeQr(String filePath) { String retStr = ""; if ("".equalsIgnoreCase(filePath) && filePath.length() == 0) { return "图片路径为空!"; } try { BufferedImage bufferedImage = ImageIO.read(new FileInputStream(filePath)); LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage); Binarizer binarizer = new HybridBinarizer(source); BinaryBitmap bitmap = new BinaryBitmap(binarizer); HashMap<DecodeHintType, Object> hintTypeObjectHashMap = new HashMap<>(); hintTypeObjectHashMap.put(DecodeHintType.CHARACTER_SET, "UTF-8"); Result result = new MultiFormatReader().decode(bitmap, hintTypeObjectHashMap); retStr = result.getText(); } catch (Exception e) { e.printStackTrace(); } return retStr; }
/** * 解析条形码 */ public static String decodes(String imgPath) { BufferedImage image = null; Result result = null; try { image = ImageIO.read(new File(imgPath)); if (image == null) { System.out.println("the decode image may be not exit."); } LuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); result = new MultiFormatReader().decode(bitmap, null); return result.getText(); } catch (Exception e) { e.printStackTrace(); } return null; }
/** * 条形码解码 * * @param imgPath 文件路径 * @return String string */ public static String decode(String imgPath) { BufferedImage image; Result result; try { image = ImageIO.read(new File(imgPath)); if (image == null) { LOGGER.error("the decode image may be not exit."); return null; } LuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); result = new MultiFormatReader().decode(bitmap, null); return result.getText(); } catch (Exception e) { LOGGER.error("条形码解析错误", e); } return null; }
/** * 二维码解码 * * @param imgPath 文件路径 * @return String string */ public static String decode2(String imgPath) { BufferedImage image; Result result; try { image = ImageIO.read(new File(imgPath)); if (image == null) { LOGGER.error("the decode image may be not exit."); return null; } LuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); EnumMap<DecodeHintType, Object> hints = new EnumMap<>(DecodeHintType.class); hints.put(DecodeHintType.CHARACTER_SET, "GBK"); result = new MultiFormatReader().decode(bitmap, hints); return result.getText(); } catch (Exception e) { LOGGER.error("二维码解码错误", e); } return null; }
/** * 读取二维码 * @param qrCodeFile * @return */ public String readQrCode(File qrCodeFile){ String ret = null; try { QRCodeReader reader = new QRCodeReader(); BufferedImage image = ImageIO.read(qrCodeFile); LuminanceSource source = new BufferedImageLuminanceSource(image); Binarizer binarizer = new HybridBinarizer(source); BinaryBitmap imageBinaryBitmap = new BinaryBitmap(binarizer); Result result = reader.decode(imageBinaryBitmap); ret = result.getText(); } catch (IOException |NotFoundException | ChecksumException | FormatException e) { Exceptions.printException(e); } return ret; }
/** * 条形码解码 * * @param imgPath * @return String */ public static String decode(String imgPath) { BufferedImage image = null; Result result = null; try { image = ImageIO.read(new File(imgPath)); if (image == null) { System.out.println("the decode image may be not exit."); } LuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); result = new MultiFormatReader().decode(bitmap, null); return result.getText(); } catch (Exception e) { e.printStackTrace(); } return null; }
/** * 二维码解码 * * @param imgPath * @return String */ public static String decode2(String imgPath) { BufferedImage image = null; Result result = null; try { image = ImageIO.read(new File(imgPath)); if (image == null) { System.out.println("the decode image may be not exit."); } LuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>(); hints.put(DecodeHintType.CHARACTER_SET, "GBK"); result = new MultiFormatReader().decode(bitmap, hints); return result.getText(); } catch (Exception e) { e.printStackTrace(); } return null; }
/** * Decode all barcodes in the image */ private String multiple(BufferedImage img) throws NotFoundException, ChecksumException, FormatException { long begin = System.currentTimeMillis(); LuminanceSource source = new BufferedImageLuminanceSource(img); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); com.google.zxing.Reader reader = new MultiFormatReader(); MultipleBarcodeReader bcReader = new GenericMultipleBarcodeReader(reader); Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>(); hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE); StringBuilder sb = new StringBuilder(); for (Result result : bcReader.decodeMultiple(bitmap, hints)) { sb.append(result.getText()).append(" "); } SystemProfiling.log(null, System.currentTimeMillis() - begin); log.trace("multiple.Time: {}", System.currentTimeMillis() - begin); return sb.toString(); }
/** * @param srcImgFilePath 要解码的图片地址 * @return */ public Result decode(String srcImgFilePath) { Result result = null; BufferedImage image; try { File srcFile = new File(srcImgFilePath); image = ImageIO.read(srcFile); if (null != image) { LuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); Hashtable hints = new Hashtable(); hints.put(DecodeHintType.CHARACTER_SET, "UTF-8"); result = new MultiFormatReader().decode(bitmap, hints); } else { log.debug("Could not decode image."); } } catch (Throwable t) { log.error("decode-ex:{}", t); throw Throwables.propagate(t); } finally { return result; } }
/** * Decodes a QR code from a BufferedImage object. * * @param image * @return a Result object containing the decoded data or information about * an unsuccessful decoding attempt * @throws Exception */ private Result decode(BufferedImage image) throws Exception { // create a luminance source from the BufferedImage LuminanceSource lumSource = new BufferedImageLuminanceSource(image); // create a binary bitmap from the luminance source. a Binarizer // converts luminance data to 1 bit data. BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(lumSource)); // a reader for decoding QRCodeReader reader = new QRCodeReader(); // attempt decoding and return result Hashtable<DecodeHintType, Boolean> hints = new Hashtable<DecodeHintType, Boolean>(); hints.put(DecodeHintType.TRY_HARDER, true); return reader.decode(bitmap, hints); }
public static String decode(BufferedImage image) { // convert the image to a binary bitmap source LuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); // decode the barcode QRCodeReader reader = new QRCodeReader(); try { @SuppressWarnings("rawtypes") Hashtable hints = new Hashtable(); Result result = reader.decode(bitmap, hints); return result.getText(); } catch (ReaderException e) { // the data is improperly formatted } return ""; }
/** * Versucht aus dem �bergeben BufferedImage ein QR Code zu finden und �bersetzt dieses in einen String. * * @param qrcodeImage : BufferedImage * @return String mit dem Inhalt des QRCodes * @throws Exception */ private static String readQRCode(BufferedImage qrcodeImage) throws Exception{ //Die Parameter anlegen Hashtable<DecodeHintType, Object> hintMap = new Hashtable<DecodeHintType, Object>(); hintMap.put(DecodeHintType.TRY_HARDER, Boolean.TRUE); //Bild zu BinaryBitmap verwandeln BufferedImageLuminanceSource source = new BufferedImageLuminanceSource(qrcodeImage); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); //QR Leser initialisieren... QRCodeReader reader = new QRCodeReader(); Result result; //...und lesen: result = reader.decode(bitmap,hintMap); return result.getText(); }
public String decode(BufferedImage image) throws NotFoundException { /*判断是否是图片*/ if (image == null) { System.out.println("Could not decode image"); } /*解析二维码用到的辅助类*/ LuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>(); /*解码设置编码方式为:UTF-8*/ hints.put(DecodeHintType.CHARACTER_SET, "UTF-8"); Result result = new MultiFormatReader().decode(bitmap, hints); String resultStr = result.getText(); return resultStr; }
private void scanQR(BufferedImage i) throws ReaderException, ChecksumException, FormatException { Image img = i.getScaledInstance(200, -1, Image.SCALE_SMOOTH); // Create a buffered image with transparency i = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB); // Draw the image on to the buffered image Graphics2D bGr = i.createGraphics(); bGr.drawImage(img, 0, 0, null); bGr.dispose(); btnDragOrPaste.setIcon(new ImageIcon(i)); BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(i))); //Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>(2); //hints.put(EncodeHintType.CHARACTER_SET, "ISO-8859-1"); //Vector decodeFormats = new Vector<BarcodeFormat>(); //decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS); //Hashtable hints = new Hashtable<DecodeHintType, Object>(3); //hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats); Result result = new QRCodeReader().decode(binaryBitmap);//, hints); //System.out.println("QR Code : "+result.getText()); textField.setText(result.getText()); //System.out.println( s ); }
private void scanQR(BufferedImage i) throws ReaderException, ChecksumException, FormatException { Image img = i.getScaledInstance(200, -1, Image.SCALE_SMOOTH); // Create a buffered image with transparency i = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB); // Draw the image on to the buffered image Graphics2D bGr = i.createGraphics(); bGr.drawImage(img, 0, 0, null); bGr.dispose(); setIcon(new ImageIcon(i)); BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(i))); //Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>(2); //hints.put(EncodeHintType.CHARACTER_SET, "ISO-8859-1"); //Vector decodeFormats = new Vector<BarcodeFormat>(); //decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS); //Hashtable hints = new Hashtable<DecodeHintType, Object>(3); //hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats); Result result = new QRCodeReader().decode(binaryBitmap);//, hints); //System.out.println("QR Code : "+result.getText()); scannedQRText = result.getText(); fireEvent(); //System.out.println( s ); }
/** * Try decoding standard QR code without any of the * sequence information inserted into payload. */ @Test public void testDecodeQrWithNoSequenceInfo() { // Decode qr code received from transmitter as screenshot String filename = "fooScreenshot_noReservedBits.png"; String expectedText = "foo"; BufferedImage b = getImageResourceAndCheckNotNull(filename); LuminanceSource lumSrc = new BufferedImageLuminanceSource(b); assertNotNull("Unable to convert BufferedImage to LuminanceSrc", lumSrc); try { Result result = Receive.decodeSingle(lumSrc); assertEquals("Expect decoded result to match expected", expectedText, result.getText()); } catch (NotFoundException e) { fail("Unable to find QR in image, "+filename + ". " + e.getMessage()); } }
public String decode(BufferedImage image) { // convert the image to a binary bitmap source LuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); // decode the barcode QRCodeReader reader = new QRCodeReader(); try { @SuppressWarnings("rawtypes") Hashtable hints = new Hashtable(); Result result = reader.decode(bitmap, hints); log.info("Decoded image successfully, result was : '" + result.getText() + "'"); return result.getText(); } catch (ReaderException e) { // the data is improperly formatted log.debug(e.getMessage()); log.error("Error while decoding image", e); } return ""; }
private static String readQrcode(BufferedImage image){ MultiFormatReader formatReader = new MultiFormatReader(); BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(image))); HashMap hints = new HashMap();//创建属性 hints.put(EncodeHintType.AZTEC_LAYERS, "utf-8");//设置编码 Result result = null; try { result = formatReader.decode(binaryBitmap,hints); } catch (NotFoundException e) { e.printStackTrace(); } System.out.println("结果 "+result.toString()); return result.toString(); }
public static String readQRCode(String filePath, String charset, Map hintMap) throws FileNotFoundException, IOException, NotFoundException { BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer( new BufferedImageLuminanceSource( ImageIO.read(new FileInputStream(filePath))))); Result qrCodeResult = new MultiFormatReader().decode(binaryBitmap, hintMap); return qrCodeResult.getText(); }
public static String decode(InputStream input) throws IOException, NotFoundException { BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer( new BufferedImageLuminanceSource( ImageIO.read(input)))); Result qrCodeResult = new MultiFormatReader().decode(binaryBitmap); return qrCodeResult.getText(); }
@Override public String read(InputStream inputStream) { try { String string = reader.decode(new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(ImageIO.read(inputStream))))).getText(); inputStream.close(); return string; } catch (Throwable e) { logger.warn(e, "读取二维码图片内容时发生异常!"); return null; } }
private static void parse() throws IOException, NotFoundException, ChecksumException, FormatException { BufferedImage image = ImageReader.readImage(Paths.get("d:/qr.png").toUri()); LuminanceSource source = new BufferedImageLuminanceSource(image); Binarizer bin = new HybridBinarizer(source); BinaryBitmap bitmap = new BinaryBitmap(bin); Result result = new QRCodeReader().decode(bitmap); System.out.println(result.toString()); }
/** * 解码 QRCode 图片,解析出其内容 * * @param imageURI QRCode 图片 URI * @return 解析后的内容 * @throws IOException */ public static String decodeQRCodeImage(URI imageURI) throws IOException { BufferedImage bufferedImage = ImageReader.readImage(imageURI); LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); QRCodeReader reader = new QRCodeReader(); try { Result result = reader.decode(bitmap); return result.getText(); } catch (ReaderException e) { e.printStackTrace(); } return ""; }
/** * Decode only one barcode */ @SuppressWarnings("unused") private String simple(BufferedImage img) throws NotFoundException, ChecksumException, FormatException { long begin = System.currentTimeMillis(); LuminanceSource source = new BufferedImageLuminanceSource(img); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); com.google.zxing.Reader reader = new MultiFormatReader(); Result result = reader.decode(bitmap); SystemProfiling.log(null, System.currentTimeMillis() - begin); log.trace("simple.Time: {}", System.currentTimeMillis() - begin); return result.getText(); }
/** * Reads the message from a code. */ private String readImage(final Exchange exchange, final InputStream stream) throws Exception { final MultiFormatReader reader = new MultiFormatReader(); final BufferedInputStream in = exchange.getContext() .getTypeConverter() .mandatoryConvertTo(BufferedInputStream.class, stream); final BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(ImageIO.read(in)))); final Result result = reader.decode(bitmap, readerHintMap); // write the found barcode format into the header exchange.getOut().setHeader(Barcode.BARCODE_FORMAT, result.getBarcodeFormat()); return result.getText(); }
private void checkFormat(File file, BarcodeFormat format) throws IOException { Reader reader = new MultiFormatReader(); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(ImageIO.read(file)))); Result result; try { result = reader.decode(bitmap); } catch (ReaderException ex) { throw new IOException(ex); } assertEquals(format, result.getBarcodeFormat()); }
/** * 解析QRCode二维码 */ @SuppressWarnings("unchecked") public static void decode(File file) { try { BufferedImage image; try { image = ImageIO.read(file); if (image == null) { System.out.println("Could not decode image"); } LuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); Result result; @SuppressWarnings("rawtypes") Hashtable hints = new Hashtable(); //解码设置编码方式为:utf-8 hints.put(DecodeHintType.CHARACTER_SET, "utf-8"); result = new MultiFormatReader().decode(bitmap, hints); String resultStr = result.getText(); System.out.println("解析后内容:" + resultStr); } catch (IOException ioe) { System.out.println(ioe.toString()); } catch (ReaderException re) { System.out.println(re.toString()); } } catch (Exception ex) { System.out.println(ex.toString()); } }
@Override public IplImage processImage(IplImage in) { LuminanceSource source = new BufferedImageLuminanceSource( in.getBufferedImage()); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); Result result; try { result = new MultiFormatReader().decode(bitmap); lastResult = result.getText(); lastFoundTime = System.currentTimeMillis(); fire(result.getText()); } catch (NotFoundException e) { // that's ok if (!lastResult.equals("")) // if result was not empty, clear old // result { long mt1 = System.currentTimeMillis(); if (mt1 - lastFoundTime > CLEAR_RESULT_TIMEOUT) { lastFoundTime = mt1; fire(""); lastResult = ""; } } } return in; }
private static String getQRCodeImageRawText(Path path) throws IOException, NotFoundException { Map<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>(); hints.put(DecodeHintType.CHARACTER_SET, StandardCharsets.UTF_8.name()); try(FileInputStream fis = new FileInputStream(path.toFile())) { BufferedImage bi = ImageIO.read(fis); BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(bi))); Result result = new MultiFormatReader().decode(binaryBitmap, hints); return result.getText(); } }
/** * 加载二维码图片得到Result对象 * @param bufferedImage 二维码图片 * @return */ public static Result loadResult(BufferedImage bufferedImage){ LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); Hashtable<DecodeHintType, String> hints = new Hashtable<DecodeHintType, String>(); hints.put(DecodeHintType.CHARACTER_SET, "UTF-8"); Result result = null; try { result = new MultiFormatReader().decode(bitmap, hints); } catch (NotFoundException e) { e.printStackTrace(); } return result; }
@Test public void testEncodeThenDecode() throws IOException { Transmit t = new Transmit(350,350); byte[] inputBytes = "foo".getBytes(Charsets.ISO_8859_1); // Generate some QR codes from input string Iterable<BitmapImage> qrCodes = null; try { qrCodes = t.encodeQRCodes(inputBytes); } catch (TransmitException e) { fail("Encoding failed "+ e.getMessage()); } Iterator<BitmapImage> iter = qrCodes.iterator(); assertTrue("QR encoding failed to return at least one element", iter.hasNext()); BitmapImage encodedQRImage = iter.next(); // Convert them to images so we can run QR decoder on them BufferedImage b = UtilsTest.toBufferedImage(encodedQRImage); LuminanceSource lumSrc = new BufferedImageLuminanceSource(b); Result result = decodeAndCheckValidQR(lumSrc, null); PartialMessage m = PartialMessage.createFromResult(result, Integer.MAX_VALUE); // Expect this small input will generate and decode a single QR code. assertNotNull("Expected QR code to be formatted for QRLib", m); assertEquals("Should only have 1 chunk" , 1, m.getTotalChunks()); assertEquals("Unexpected chunkId" , 1, m.getChunkId()); assertArrayEquals("Original input does not match decoded result", inputBytes,m.getPayload()); }
/** * Opens a test file in resources directory and converts it to ZXing's * LuminanceSource image type. Causes unit tests to fail if conversion fails. * * @param filename The image file that will be converted. */ private LuminanceSource getLuminanceImgAndCheckNotNull(String filename) { BufferedImage b = getImageResourceAndCheckNotNull(filename); LuminanceSource lumSrc = new BufferedImageLuminanceSource(b); assertNotNull("Unable to convert BufferedImage to LuminanceSrc", lumSrc); return lumSrc; }
/** * Convert from Java's BufferedImage type to ZXing's BitMatrix type. * Returns null when there is no QR code found in the image. * * @param img The BufferedImage to convert to BitMatrix * @return The BitMatrix of the QR code found in img */ private static BitMatrix toBitMatrix (BufferedImage img){ BufferedImageLuminanceSource lumSrc = new BufferedImageLuminanceSource(img); HybridBinarizer hb = new HybridBinarizer(lumSrc); try { return hb.getBlackMatrix(); } catch (NotFoundException e) { // Ok to ignore, returning null when QR code not found. // PMD complained about empty catch block return null; } }