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;
}
}