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

    package shjt.license.util;
    
    import java.awt.Color;
    import java.awt.Graphics2D;
    import java.awt.image.BufferedImage;
    import java.io.File;
    
    import javax.imageio.ImageIO;
    
    import com.swetake.util.Qrcode;
    
    public class QRcodeUtil {
    
    	static int width = 90;
    	static int height = 90;
    
    	public static String getQRcode(String filepath) {
    		try {
    			Qrcode testQrcode = new Qrcode();
    
    			testQrcode.setQrcodeErrorCorrect('M');
    
    			testQrcode.setQrcodeEncodeMode('B');
    
    			testQrcode.setQrcodeVersion(7);
    
    			String testString = "http://218.242.180.164:8001/";
    
    			byte[] d = testString.getBytes("gbk");
    
    			BufferedImage bi = new BufferedImage(width, height, 12);
    
    			Graphics2D g = bi.createGraphics();
    
    			g.setBackground(Color.WHITE);
    
    			g.clearRect(0, 0, width, height);
    
    			g.setColor(Color.BLACK);
    
    			if ((d.length > 0) && (d.length < 120)) {
    				boolean[][] s = testQrcode.calQrcode(d);
    				for (int i = 0; i < s.length; i++) {
    					for (int j = 0; j < s.length; j++) {
    						if (s[j][i]) {
    							g.fillRect(j * 2, i * 2, 2, 2);
    						}
    					}
    
    				}
    
    			}
    
    			g.dispose();
    
    			bi.flush();
    
    			File f = new File(filepath);
    
    			if (!f.exists())
    				f.mkdirs();
    			ImageIO.write(bi, "jpg", f);
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    
    		return filepath;
    	}
    }
    

      

  • 相关阅读:
    Codeforces Round #281 (Div. 2) A. Vasya and Football(模拟)
    自动生成代码工具
    导入导出维护计划
    收集错误日志方法
    C#常用控件和属性
    人民币转换
    身份证验证
    设置下拉列表项的默认值
    清除维护任务
    清除MSSQL历史记录
  • 原文地址:https://www.cnblogs.com/1025804158ysb/p/7489076.html
Copyright © 2011-2022 走看看