打印二维码(jdk1.5可用)

3 篇文章 0 订阅


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


}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值