最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

java二維碼生成的方法

 更新時(shí)間:2017年06月07日 09:21:14   作者:ITqingliang  
這篇文章主要為大家詳細(xì)介紹了java二維碼生成的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了java二維碼的實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下

這次用到的jar包是zxing,沒有用到core的jar包
先導(dǎo)入zxing.jar包

生成二維碼

package cn.huse.erweima;

import java.io.File;
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 = "gif";
 String content = "www.baidu.com";
 
 //定義二維碼的參數(shù)
 HashMap hints = new HashMap<>();
 hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
 hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
 try {
  BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height,hints);
  File file = new File("e:"+File.separator+"new.gif");
  MatrixToImageWriter.writeToFile(matrix, format, file);
 } catch (Exception e) {
  e.printStackTrace();
 }
 }

}


解析二維碼

package cn.huse.erweima;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import javax.imageio.ImageIO;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.NotFoundException;
import com.google.zxing.Result;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;

//解析二維碼
public class ReadQRCode {

 public static void main(String[] args) {
 
 MultiFormatReader formatReader = new MultiFormatReader();
 File file = new File("e:"+File.separator+"new.gif");
 try {
  BufferedImage image = ImageIO.read(file);
  BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(image)));
  HashMap hints = new HashMap<>();
  hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
  
  Result result = formatReader.decode(binaryBitmap,hints);
  System.out.println(result.toString());
  System.out.println(result.getBarcodeFormat());
  System.out.println(result.getText());
 } catch (NotFoundException e) {
  e.printStackTrace();
 } catch (IOException e) {
  e.printStackTrace();
 }
 }

}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • IDEA類和方法注釋模板設(shè)置(非常詳細(xì))

    IDEA類和方法注釋模板設(shè)置(非常詳細(xì))

    這篇文章主要介紹了IDEA類和方法注釋模板設(shè)置(非常詳細(xì)),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-08-08
  • 一篇帶你入門Java垃圾回收器

    一篇帶你入門Java垃圾回收器

    垃圾收集器是垃圾回收算法(標(biāo)記-清除算法、復(fù)制算法、標(biāo)記-整理算法、火車算法)的具體實(shí)現(xiàn),不同商家、不同版本的JVM所提供的垃圾收集器可能會有很在差別
    2021-06-06
  • Spring Boot中使用Activiti的方法教程(二)

    Spring Boot中使用Activiti的方法教程(二)

    工作流(Workflow),就是“業(yè)務(wù)過程的部分或整體在計(jì)算機(jī)應(yīng)用環(huán)境下的自動化”,下面這篇文章主要給大家介紹了關(guān)于Spring Boot中使用Activiti的相關(guān)資料,需要的朋友可以參考下
    2018-08-08
  • PowerJob的MapProcessor工作流程源碼解讀

    PowerJob的MapProcessor工作流程源碼解讀

    這篇文章主要為大家介紹了PowerJob的MapProcessor工作流程源碼解讀,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2024-01-01
  • 最新評論

    霞浦县| 蛟河市| 都兰县| 临漳县| 夏津县| 临颍县| 成武县| 溧水县| 田林县| 河北区| 浮梁县| 神木县| 同江市| 邵东县| 咸阳市| 巩义市| 余姚市| 湟源县| 石嘴山市| 张掖市| 丹阳市| 织金县| 乐业县| 荣昌县| 工布江达县| 互助| 广丰县| 广元市| 建阳市| 奉贤区| 区。| 福鼎市| 阿尔山市| 邵阳县| 开鲁县| 嵩明县| 凤凰县| 新竹县| 城口县| 青海省| 屏南县|