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

      

  • 相关阅读:
    响应式开发
    css3的2D和3D的转换
    前端CSS3笔记
    DOM精简版笔记
    JS进阶
    linux 修改时间同步到BIOS
    linux-设置代理和取消代理
    linux-rpm强制安装跳过依赖包
    [linux] VNC the connection was refused by the computer
    Linux vim 常用命令(不定时update)
  • 原文地址:https://www.cnblogs.com/Jansens520/p/7735937.html
Copyright © 2020-2023  润新知