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

      

  • 相关阅读:
    堆优化Dijkstra模版
    poj_1364King
    快速排序库函数qsort的使用
    CMD type命令
    开放地址法
    poj_3159Candies
    poj_1511Invitation Cards
    何谓数据结构
    div ul li添加文本自动自动
    java虚拟机使用内存
  • 原文地址:https://www.cnblogs.com/Jansens520/p/7735937.html
Copyright © 2011-2022 走看看