当前位置: 首页>>代码示例>>Java>>正文


Java EAN13Writer类代码示例

本文整理汇总了Java中com.google.zxing.oned.EAN13Writer的典型用法代码示例。如果您正苦于以下问题:Java EAN13Writer类的具体用法?Java EAN13Writer怎么用?Java EAN13Writer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


EAN13Writer类属于com.google.zxing.oned包,在下文中一共展示了EAN13Writer类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getProductEAN

import com.google.zxing.oned.EAN13Writer; //导入依赖的package包/类
@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);
}
 
开发者ID:thomasletsch,项目名称:moserp,代码行数:17,代码来源:ProductController.java

示例2: createBarCode

import com.google.zxing.oned.EAN13Writer; //导入依赖的package包/类
public static InputStream createBarCode(long inputId) {
	
	try {
		EAN13Writer wt = new EAN13Writer();
		String data = String.format("%012d", inputId);
		int check = getStandardUPCEANChecksum(data);
        data += check;
		BitMatrix bt = wt.encode(data, BarcodeFormat.EAN_13, 200, 50);
		int width = bt.getWidth();
	    int height = bt.getHeight();
	    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
	    int[] pixels = new int[width * height];
	    int index = 0;
	    for (int y = 0; y < height; y++) {
	    	for (int x = 0; x < width; x++) {
	    		pixels[index++] = bt.get(x, y) ? Color.BLACK.hashCode() : Color.WHITE.hashCode();
	    	}
	    }
	    image.setRGB(0, 0, width, height, pixels, 0, width);
	    ByteArrayOutputStream out = new ByteArrayOutputStream();
	    ImageIO.write(image, "png", out);
	    return new ByteArrayInputStream(out.toByteArray());
	} catch (FormatException | WriterException | IOException e) {
       	e.printStackTrace();
       }
    
	return null;
}
 
开发者ID:axelor,项目名称:axelor-business-suite,代码行数:29,代码来源:BarcodeGeneratorService.java

示例3: generateEAN13

import com.google.zxing.oned.EAN13Writer; //导入依赖的package包/类
public static BitMatrix generateEAN13(String content, int width, int height) throws WriterException {
    return new EAN13Writer().encode(content, BarcodeFormat.EAN_13, width, height);

}
 
开发者ID:ScilCoop,项目名称:pasteque-android,代码行数:5,代码来源:BarcodeGenerator.java


注:本文中的com.google.zxing.oned.EAN13Writer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。