use of com.google.zxing.MultiFormatReader in project zxing-android-embedded by journeyapps.
the class DefaultDecoderFactory method createDecoder.
@Override
public Decoder createDecoder(Map<DecodeHintType, ?> baseHints) {
Map<DecodeHintType, Object> hints = new EnumMap<>(DecodeHintType.class);
hints.putAll(baseHints);
if (this.hints != null) {
hints.putAll(this.hints);
}
if (this.decodeFormats != null) {
hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
}
if (characterSet != null) {
hints.put(DecodeHintType.CHARACTER_SET, characterSet);
}
MultiFormatReader reader = new MultiFormatReader();
reader.setHints(hints);
return inverted ? new InvertedDecoder(reader) : new Decoder(reader);
}
use of com.google.zxing.MultiFormatReader in project camel by apache.
the class BarcodeDataFormat method readImage.
/**
* 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();
}
use of com.google.zxing.MultiFormatReader in project camel by apache.
the class BarcodeTestBase method checkFormat.
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());
}
use of com.google.zxing.MultiFormatReader in project zxing by zxing.
the class DecodeWorker method decode.
private Result[] decode(URI uri, Map<DecodeHintType, ?> hints) throws IOException {
BufferedImage image = ImageReader.readImage(uri);
LuminanceSource source;
if (config.crop == null) {
source = new BufferedImageLuminanceSource(image);
} else {
List<Integer> crop = config.crop;
source = new BufferedImageLuminanceSource(image, crop.get(0), crop.get(1), crop.get(2), crop.get(3));
}
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
if (config.dumpBlackPoint) {
dumpBlackPoint(uri, image, bitmap);
}
MultiFormatReader multiFormatReader = new MultiFormatReader();
Result[] results;
try {
if (config.multi) {
MultipleBarcodeReader reader = new GenericMultipleBarcodeReader(multiFormatReader);
results = reader.decodeMultiple(bitmap, hints);
} else {
results = new Result[] { multiFormatReader.decode(bitmap, hints) };
}
} catch (NotFoundException ignored) {
System.out.println(uri + ": No barcode found");
return null;
}
if (config.brief) {
System.out.println(uri + ": Success");
} else {
StringWriter output = new StringWriter();
for (Result result : results) {
ParsedResult parsedResult = ResultParser.parseResult(result);
output.write(uri + " (format: " + result.getBarcodeFormat() + ", type: " + parsedResult.getType() + "):\n" + "Raw result:\n" + result.getText() + "\n" + "Parsed result:\n" + parsedResult.getDisplayResult() + "\n");
output.write("Found " + result.getResultPoints().length + " result points.\n");
for (int pointIndex = 0; pointIndex < result.getResultPoints().length; pointIndex++) {
ResultPoint rp = result.getResultPoints()[pointIndex];
output.write(" Point " + pointIndex + ": (" + rp.getX() + ',' + rp.getY() + ')');
if (pointIndex != result.getResultPoints().length - 1) {
output.write('\n');
}
}
output.write('\n');
}
System.out.println(output);
}
return results;
}
use of com.google.zxing.MultiFormatReader in project zxing by zxing.
the class GUIRunner method getDecodeText.
private static String getDecodeText(Path file) {
BufferedImage image;
try {
image = ImageReader.readImage(file.toUri());
} catch (IOException ioe) {
return ioe.toString();
}
LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Result result;
try {
result = new MultiFormatReader().decode(bitmap);
} catch (ReaderException re) {
return re.toString();
}
return String.valueOf(result.getText());
}
Aggregations