• 二维码


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

      

  • 相关阅读:
    AJAX
    JQUERY基础
    PHP 数据库抽象层pdo
    会话控制:session与cookie
    php 如何造一个简短原始的数据库类用来增加工作效率
    php 数据访问(以mysql数据库为例)
    面向对象设计原则
    php 设计模式 例子
    PHP中静态与抽象的概念
    键盘的按钮键名
  • 原文地址:https://www.cnblogs.com/1025804158ysb/p/7489076.html
Copyright © 2020-2023  润新知