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

      

  • 相关阅读:
    js38---门面模式
    js37---Function.prototype
    js36---函数嵌套
    js35
    js34
    js33--责任链模式
    js32---CommonUtil.js
    龙芯服务器参数
    SQLSERVER 秘钥整理
    IOMETER的简单使用
  • 原文地址:https://www.cnblogs.com/1025804158ysb/p/7489076.html
Copyright © 2011-2022 走看看