您的位置:首页 > 编程语言 > Go语言

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

2016-05-20 17:22 706 查看
生成二维码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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  google zxing url 二维码