国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Java > 正文

Java中基于maven實現zxing二維碼功能

2019-11-26 13:09:32
字體:
來源:轉載
供稿:網友

maven所需jar

<dependency>  <groupId>com.google.zxing</groupId>  <artifactId>core</artifactId>  <version>3.0.0</version>  </dependency>  <dependency>  <groupId>com.google.zxing</groupId>  <artifactId>javase</artifactId>  <version>3.0.0</version>    </dependency>

生成二維碼:

public static void main(String[] args) throws IOException {String text="www.baidu.com";int width=100;int height=100;String format="png";Hashtable hints=new Hashtable();hints.put(EncodeHintType.CHARACTER_SET, "utf-8");hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);hints.put(EncodeHintType.MARGIN, 2);try {BitMatrix bitMatrix=new MultiFormatWriter().encode(text, BarcodeFormat.QR_CODE, width, height,hints); Path file=new Java.io.File("D:/new.png").toPath();MatrixToImageWriter.writeToPath(bitMatrix, format, file);} catch (WriterException e) {// TODO Auto-generated catch blocke.printStackTrace();}解析二維碼:public static void main(String[] args) throws NotFoundException {MultiFormatReader formatReader=new MultiFormatReader();File file =new File("D:/new.png");BufferedImage image=null;try {image = ImageIO.read(file);} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}BinaryBitmap binaryBitmap =new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(image)));Hashtable hints=new Hashtable();hints.put(EncodeHintType.CHARACTER_SET, "utf-8");Result result=formatReader.decode(binaryBitmap,hints);System.err.println("解析結果:"+result.toString());System.out.println(result.getBarcodeFormat());System.out.println(result.getText());}

以上所述是小編給大家介紹的Java中基于maven實現zxing二維碼功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 济南市| 保山市| 松溪县| 东丽区| 连南| 包头市| 饶阳县| 水富县| 阳信县| 马龙县| 乌鲁木齐县| 商水县| 班玛县| 阳曲县| 遵义县| 仁寿县| 泸定县| 衡山县| 牡丹江市| 太湖县| 望江县| 商南县| 汤阴县| 思茅市| 托克逊县| 大名县| 崇文区| 建湖县| 江陵县| 锡林浩特市| 文成县| 慈利县| 彭泽县| 郎溪县| 达孜县| 呼伦贝尔市| 海原县| 郸城县| 万宁市| 赫章县| 剑河县|