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

      

  • 相关阅读:
    万能的everything彻底解决mysql问题
    乱码问题
    机器学习学习规划
    NG机器学习笔记
    书籍与博客
    技术规划
    反置数
    多个接口出现同名函数的处理-转
    接口-imploements-委托
    接口使用中,对象生命周期管理-转
  • 原文地址:https://www.cnblogs.com/Jansens520/p/7735937.html
Copyright © 2011-2022 走看看