• 二维码生成


    如果觉得对您有帮助请关注加粉丝,谢谢!

    package com.bbtree.project.weixin;

    import com.swetake.util.Qrcode;

    import javax.imageio.ImageIO;
    import java.awt.*;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.util.Base64;

    /**
    * Created by Administrator on 2017/1/6.
    */
    //微信二维码生成代码
    public class WeixinCode {
    public static void main(String[] args) {
    String data="柳阮真我爱你!!";
    /**
    * 生成二维码
    */
    encode(data,"F:/weixin/点开有惊喜.JPG");

    /**
    * 解释二维码
    */
    //decode(""C:\\Users\\Administrator\\Desktop\\桌面壁纸"");
    }

    /**
    * 对应的生成二维码的方法
    * @return
    */
    public static boolean encode(String srcValue,String qrcodePicfilePath){
    int MAX_DATA_LENGTH=200;
    byte[] d=srcValue.getBytes();
    int dataLength=d.length;
    int imageWidth=113;
    int imageHeight=imageWidth;
    BufferedImage bi = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_3BYTE_BGR);
    Graphics2D g=bi.createGraphics();
    g.setBackground(Color.WHITE);
    g.clearRect(0,0,imageWidth,imageHeight);
    g.setColor(Color.BLACK);
    if (dataLength>0&&dataLength<=MAX_DATA_LENGTH){
    Qrcode qrcode = new Qrcode();
    qrcode.setQrcodeErrorCorrect('M');
    qrcode.setQrcodeEncodeMode('B');
    qrcode.setQrcodeVersion(5);
    boolean[][] b = qrcode.calQrcode(d);
    int qrodeDataLen=b.length;
    for (int i=0;i<qrodeDataLen;i++){
    for (int j=0;j<qrodeDataLen;j++){
    if (b[j][i]){
    g.fillRect(j*3+2,i*3+2,3,3);
    }
    }
    }
    System.out.println("二维码成功生成!!");
    }else{
    System.out.println(dataLength+"大于"+MAX_DATA_LENGTH);
    return false;
    }
    g.dispose();
    bi.flush();
    File f = new File(qrcodePicfilePath);
    String suffix=f.getName().
    substring(f.getName().indexOf(".")+1,f.getName().length());
    System.out.println("二维码输出成功!!");
    try {
    ImageIO.write(bi,suffix,f);
    }catch (IOException ioe){
    System.out.println("二维码生成失败"+ioe.getMessage());
    return false;
    }
    return true;
    }
    }

     

  • 相关阅读:
    WebForms UnobtrusiveValidationMode 须要“jquery”ScriptResourceMapping。
    用R进行微博分析的初步尝试
    使用Docker部署Gitlab
    怎样托管你的项目到github上具体教程
    Android Api Demos登顶之路(四十五)Loader--&gt;Cursor
    【C语言】推断一个数是否为2的n次方
    Akka并发编程——第五节:Actor模型(四)
    POJ2773 Happy 2006【容斥原理】
    作用域与生命周期
    C# string
  • 原文地址:https://www.cnblogs.com/chenxqNo01/p/6370641.html
Copyright © 2020-2023  润新知