利用googleZxing生成二维码识别二维码

来源:互联网 发布:金立gn106软件下载 编辑:程序博客网 时间:2024/05/16 09:00
生成二维码ImageIO流:

<span style="color:#FF6666;">MultiFormatWriter multiFormatWriter = new MultiFormatWriter();BitMatrix bitMatrix = multiFormatWriter.encode(url, BarcodeFormat.QR_CODE, 140, 140);BufferedImage image = MatrixToImageWriter.toBufferedImage(bitMatrix);ByteArrayOutputStream out = new ByteArrayOutputStream();ImageIO.write(image, "jpg", out);</span>


识别二维码:


<span style="color:#FF6666;">String imgUrl = "*.com/a.jpg"URL url = new URL(imgUrl);image = ImageIO.read(url);LuminanceSource source = new BufferedImageLuminanceSource(image);    Binarizer binarizer = new HybridBinarizer(source);BinaryBitmap binaryBitmap = new BinaryBitmap(binarizer);MultiFormatReader uultiFormatReader = new MultiFormatReader();Result result = uultiFormatReader.decode(binaryBitmap);return result.getText();</span>

maven依赖:
<span style="color:#FF0000;"><dependency>    <groupId>com.google.zxing</groupId>        <artifactId>core</artifactId>    <version>2.3.0</version></dependency><dependency>    <groupId>com.google.zxing</groupId>        <artifactId>javase</artifactId>    <version>2.2</version></dependency></span>

注:本人应用版本2.3.0,识别二维码时遇到问题,
<span style="background-color: rgb(0, 153, 0);"><span style="font-size:24px;">javase包JDK版本1.7 如Java6项目,请将javase版本降级为2.2</span></span>下载包地址:<span style="font-family:Helvetica, 'Hiragino Sans GB', 'Microsoft Yahei', SimSun, SimHei, arial, sans-serif;color:#000000;font-size: 15.238096237182617px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22.85714340209961px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; display: inline !important; float: none;">http://mvnrepository.com/</span>


0 0