zxing-1.7-core.jar
http://www.java2s.com/Code/Jar/z/Downloadzxing17corejar.htm
zxing-1.7-javase.jar
http://www.java2s.com/Code/Jar/z/Downloadzxing17javasejar.htm
java代码
输出byte[]
import java.io.ByteArrayOutputStream;
import java.util.Hashtable;
import com.eos.system.annotation.Bizlet;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
public class CreateQrcode {
@Bizlet("生成二维码 ")
public static byte[] getQRcode(String code) {
ByteArrayOutputStream ret = new ByteArrayOutputStream();
try {
BitMatrix byteMatrix;
Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
//hints.put(EncodeHintType.MARGIN, 1); //设置二维码空白边框的大小 1-4,1是最小 4是默认的国标
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
//// 参数顺序分别为:编码内容,编码类型,生成图片宽度,生成图片高度,设置参数
byteMatrix = new MultiFormatWriter().encode(new String(code.getBytes("UTF-8"),"iso-8859-1"),
BarcodeFormat.QR_CODE, 200, 200,hints);
MatrixToImageWriter.writeToStream(byteMatrix, "png", ret);
byte[] b=ret.toByteArray();
ret.close();
return b;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

本文提供了一个使用Java生成二维码的示例代码,利用ZXing库实现从字符串到QR码图像的转换,并提供了完整的错误处理机制。
&spm=1001.2101.3001.5002&articleId=77021597&d=1&t=3&u=d5901d2981a14555b4157b91efba8458)
464

被折叠的 条评论
为什么被折叠?



