public class oCBX { private static BarcodeFormat DEFAULT_BARCODE_FORMAT = BarcodeFormat.CODABAR; public static String decode(File whatFile, Map<DecodeHintType, Object> whatHints) throws Exception { if (whatFile == null || whatFile.getName().trim().isEmpty()) throw new IllegalArgumentException("File not found, or invalid file name."); BufferedImage tmpBfrImage; try { tmpBfrImage = ImageIO.read(whatFile); } catch (IOException tmpIoe) { throw new Exception(tmpIoe.getMessage()); } if (tmpBfrImage == null) throw new IllegalArgumentException("Could not decode image."); LuminanceSource tmpSource = new BufferedImageLuminanceSource(tmpBfrImage); BinaryBitmap tmpBitmap = new BinaryBitmap(new HybridBinarizer(tmpSource)); MultiFormatReader tmpBarcodeReader = new MultiFormatReader(); Result tmpResult; String tmpFinalResult; try { if (whatHints != null && ! whatHints.isEmpty()) tmpResult = tmpBarcodeReader.decode(tmpBitmap, whatHints); else tmpResult = tmpBarcodeReader.decode(tmpBitmap); tmpFinalResult = String.valueOf(tmpResult.getText()); } catch (Exception tmpExcpt) { throw new Exception("BarCodeUtil.decode Excpt err - " + tmpExcpt.toString() + " - " + tmpExcpt.getMessage()); } return tmpFinalResult; } public static void main(String[] args){ try { Map<DecodeHintType,Object> tmpHintsMap = new EnumMap<DecodeHintType, Object>(DecodeHintType.class); tmpHintsMap.put(DecodeHintType.TRY_HARDER, Boolean.TRUE); tmpHintsMap.put(DecodeHintType.POSSIBLE_FORMATS, EnumSet.allOf(BarcodeFormat.class)); tmpHintsMap.put(DecodeHintType.PURE_BARCODE, Boolean.FALSE); File tmpFile = new File("c:\\bc\\im\\7.tif"); String tmpRetString = oCBX.decode(tmpFile, tmpHintsMap); System.out.println(tmpRetString); } catch (Exception tmpExpt) { System.out.println("main: " + "Excpt err! (" + tmpExpt.getMessage() + ")"); } System.out.println("main: " + "Program end."); } }