最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Java中基于maven实现zxing二维码功能
时间:2017-03-13 编辑:简简单单 来源:一聚教程网
maven所需jar
代码如下 | 复制代码 |
|
生成二维码:
代码如下 | 复制代码 |
publicstaticvoidmain(String[] args)throwsIOException { String text="www.baidu.com"; intwidth=100; intheight=100; String format="png"; Hashtable hints=newHashtable(); hints.put(EncodeHintType.CHARACTER_SET,"utf-8"); hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M); hints.put(EncodeHintType.MARGIN,2); try{ BitMatrix bitMatrix=newMultiFormatWriter().encode(text, BarcodeFormat.QR_CODE, width, height,hints); Path file=newJava.io.File("D:/new.png").toPath(); MatrixToImageWriter.writeToPath(bitMatrix, format, file); }catch(WriterException e) { // TODO Auto-generated catch block e.printStackTrace(); } 解析二维码: publicstaticvoidmain(String[] args)throwsNotFoundException { MultiFormatReader formatReader=newMultiFormatReader(); File file =newFile("D:/new.png"); BufferedImage image=null; try{ image = ImageIO.read(file); }catch(IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } BinaryBitmap binaryBitmap =newBinaryBitmap(newHybridBinarizer(newBufferedImageLuminanceSource(image))); Hashtable hints=newHashtable(); 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()); } |
相关文章
- 扫描二维码聊天套路资源哪里有 微信聊天扫码查看我的悄悄话 09-10
- 派派二维码如何添加好友 08-07
- wps如何制作二维码名片 07-19
- 银联云闪付二维码怎么支付 06-01
- iOS自带原生二维码扫描的实现 01-14
- MIUI相机扫描二维码使用图文教程 10-19