ZXing 条形码处理类库开源项目

我要开发同款
匿名用户2009年06月24日
100阅读

技术信息

开源地址
https://github.com/zxing/zxing
授权协议
Apache

作品详情

ZXig是一个开源Java类库用于解析多种格式的1D/2D条形码。目标是能够对QR编码、DataMatrix、UPC的1D条形码进行解码。其提供了多种平台下的客户端包括:J2ME、J2SE和Adroid。

示例代码:

import com.google.zxig.BarcodeFormat;import com.google.zxig.EcodeHitType;import com.google.zxig.MultiFormatWriter;import com.google.zxig.WriterExceptio;import com.google.zxig.cliet.j2se.MatrixToImageWriter;import com.google.zxig.commo.BitMatrix;import com.google.zxig.qrcode.decoder.ErrorCorrectioLevel;import java.io.File;import java.io.IOExceptio;import java.io.OutputStream;import java.util.HashMap;import java.util.Map;/*** 二维码工具类*/public class QRCodeUtil {  private static fial it width = 300;// 默认二维码宽度  private static fial it height = 300;// 默认二维码高度  private static fial Strig format = "pg";// 默认二维码文件格式  private static fial Map<EcodeHitType, Object> hits = ew HashMap();// 二维码参数  static {      hits.put(EcodeHitType.CHARACTER_SET, "utf-8");// 字符编码      hits.put(EcodeHitType.ERROR_CORRECTION, ErrorCorrectioLevel.H);// 容错等级 L、M、Q、H 其中 L 为最低, H 为最高      hits.put(EcodeHitType.MARGIN, 2);// 二维码与图片边距  }  /**   * 返回一个 BufferedImage 对象   * @param cotet 二维码内容   * @param width   宽   * @param height  高   */  public static BufferedImage toBufferedImage(Strig cotet, it width, it height) throws WriterExceptio, IOExceptio {      BitMatrix bitMatrix = ew MultiFormatWriter().ecode(cotet, BarcodeFormat.QR_CODE, width, height, hits);      retur MatrixToImageWriter.toBufferedImage(bitMatrix);  }  /**   * 将二维码图片输出到一个流中   * @param cotet 二维码内容   * @param stream  输出流   * @param width   宽   * @param height  高   */  public static void writeToStream(Strig cotet, OutputStream stream, it width, it height) throws WriterExceptio, IOExceptio {      BitMatrix bitMatrix = ew MultiFormatWriter().ecode(cotet, BarcodeFormat.QR_CODE, width, height, hits);      MatrixToImageWriter.writeToStream(bitMatrix, format, stream);  }  /**   * 生成二维码图片文件   * @param cotet 二维码内容   * @param path    文件保存路径   * @param width   宽   * @param height  高   */  public static void createQRCode(Strig cotet, Strig path, it width, it height) throws WriterExceptio, IOExceptio {      BitMatrix bitMatrix = ew MultiFormatWriter().ecode(cotet, BarcodeFormat.QR_CODE, width, height, hits);      //toPath() 方法由 jdk1.7 及以上提供      MatrixToImageWriter.writeToPath(bitMatrix, format, ew File(path).toPath());  }}

功能介绍

ZXing是一个开源Java类库用于解析多种格式的1D/2D条形码。目标是能够对QR编码、Data Matrix、UPC的1D条形码进行解码。 其提供了多种平台下的客户端包括:J2ME、J2SE...

示例图片

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论