Java生成条码二维码

一、概述

可用barcode4j或zxing等第三方库,推荐zxing。

barcode4j资料链接:http://barcode4j.sourceforge.net/

zxing资料链接:https://github.com/zxing/zxing

二、barcode4j

关键代码:

DataMatrixBean bean = new DataMatrixBean();
final int dpi = 800;
String format = "image/png";
ByteArrayOutputStream ous = new ByteArrayOutputStream();
BitmapCanvasProvider canvas = new BitmapCanvasProvider(ous, format, dpi,BufferedImage.TYPE_BYTE_BINARY, false, 0); 
bean.generateBarcode(canvas, info);
canvas.finish(); 

 支持的条码格式有:

  • Interleaved 2 of 5
  • ITF-14
  • Code 39
  • Code 128
  • EAN-128, GS1-128 (based on Code 128)
  • Codabar
  • UPC-A and UPC-E (with supplementals)
  • EAN-13 and EAN-8 (with supplementals)
  • POSTNET
  • Royal Mail Customer Barcode (Four State)
  • USPS Intelligent Mail (4-State Customer Barcode)

支持的二维码格式有:

  • PDF 417 (ISO/IEC 15438:2001(E))
  • DataMatrix (ISO/IEC 16022:2000(E))
  • QR Code (ISO/IEC 18004:2006(E)) (requires ZXing, available from CVS HEAD only)

可输出文件类型为:

  • SVG
  • EPS (Encapsulated PostScript)
  • Bitmap images (such as PNG or JPEG)
  • Java2D (AWT)
  • Text (for testing and debugging only)
posted @ 2018-03-16 15:52  马洪彪  阅读(536)  评论(0编辑  收藏  举报