com.google.zxing.oned.EAN13Writer Java Examples

The following examples show how to use com.google.zxing.oned.EAN13Writer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProductController.java    From moserp with Apache License 2.0 6 votes vote down vote up
@ResponseBody
@RequestMapping(method = RequestMethod.GET, value = "/{productId}/ean")
public ResponseEntity<?> getProductEAN(@PathVariable String productId) throws WriterException, IOException {
    Product product = repository.findOne(productId);
    if (product == null) {
        return ResponseEntity.notFound().build();
    }
    EAN13Writer ean13Writer = new EAN13Writer();
    BitMatrix matrix = ean13Writer.encode(product.getEan(), BarcodeFormat.EAN_13, 300, 200);
    BufferedImage bufferedImage = MatrixToImageWriter.toBufferedImage(matrix);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(bufferedImage, "png", baos);
    byte[] imageData = baos.toByteArray();
    ByteArrayResource byteArrayResource = new ByteArrayResource(imageData);
    return ResponseEntity.ok().contentType(MediaType.IMAGE_PNG).body(byteArrayResource);
}
 
Example #2
Source File: ZxingBarcodeGenerator.java    From tutorials with MIT License 4 votes vote down vote up
public static BufferedImage generateEAN13BarcodeImage(String barcodeText) throws Exception {
    EAN13Writer barcodeWriter = new EAN13Writer();
    BitMatrix bitMatrix = barcodeWriter.encode(barcodeText, BarcodeFormat.EAN_13, 300, 150);

    return MatrixToImageWriter.toBufferedImage(bitMatrix);
}