zoukankan      html  css  js  c++  java
  • java二维码生成

    import java.io.File;
    import java.nio.file.Path;
    import java.util.HashMap;
    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 {
    
    	public static void main(String[] args) {
    		int width=300;
    		int height=300;
            String format="jpg";
            String content="http://www.zjjansens.com";
            //定义二维码参数
            HashMap hashMap=new HashMap();
            hashMap.put(EncodeHintType.CHARACTER_SET, "UTF-8");
            hashMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
            hashMap.put(EncodeHintType.MARGIN,2);                        
            try {
    			BitMatrix bitMatrix=new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height,hashMap);
    			Path file=new File("d:/img.jpg").toPath();
    			MatrixToImageWriter.writeToPath(bitMatrix,format, file);;
    		} catch (Exception e) {
    			e.printStackTrace();
    		}                
    	}
    }
    

      

  • 相关阅读:
    java笔试之输出
    构造块和静态块[转]
    Java 对象和类
    StringBuffer
    基于bootstrap的表格数据展示
    弹窗式页面
    读取xml
    更新xml
    写XML
    遍历一个类的字段和值
  • 原文地址:https://www.cnblogs.com/Jansens520/p/7735937.html
Copyright © 2011-2022 走看看