系列文章:[传送门]
上几周碌碌无为,不行啊不行啊。博客园,不知道你几时改版。老家了,我不会忘记你呢。呵呵,我也会在os,csdn更新的。每天一搏,不管有用没用。
正文先有项目起步,项目中的需求很明确。
利用二维码扫描,然后实现签到功能。
自然和app挂钩。 没事,一步一步来。
二维码(QR(Quick Response)code),又称二维条码,它是用特定的几何图形按一定规律在平面(二维方向)上分布的黑白相间的图形,是所有信息数据的一把钥匙。
ZXing是一个开放源码的,用Java实现的多种格式的1D/2D条码图像处理库,它包含了联系到其他语言的端口。Zxing可以实现使用手机的内置的摄像头完成条形码的扫描及解码。该项目可实现的条形码编码和解码
大家可以去了解
https://github.com/zxing/zxing/wiki/Getting-Started-Developing
#BitMatrix 设置参数顺序分别为:编码内容,编码类型,生成图片宽度,生成图片高度,设置参数
#MatrixToImageWriter 生成所需要的文件
你会找到这个图片
/** * 解码 * @param imgPath 二维码图片路径 * @return */ package sedion.jeffli.wmuitp.util.zxing; import java.awt.image.BufferedImage; import java.io.File; import java.util.Hashtable; import javax.imageio.ImageIO; import com.google.zxing.BinaryBitmap; import com.google.zxing.DecodeHintType; import com.google.zxing.LuminanceSource; import com.google.zxing.MultiFormatReader; import com.google.zxing.Result; import com.google.zxing.client.j2se.BufferedImageLuminanceSource; import com.google.zxing.common.HybridBinarizer; /** * @author Jeff Lee */ public class ZxingDecoderHandler { /** * 解码 * @param imgPath 二维码图片路径 * @return */ public String decode(String imgPath) { BufferedImage image = null; Result result = null; try { image = ImageIO.read(new File(imgPath)); if (image == null) { System.out.println("文件不存在!"); //应该抛个异常的 } LuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>(); hints.put(DecodeHintType.CHARACTER_SET, "utf-8"); result = new MultiFormatReader().decode(bitmap, hints); return result.getText(); } catch (Exception e) { e.printStackTrace(); } return null; } public static void main(String[] args) { String imgPath = "d:/33.png"; ZxingDecoderHandler handler = new ZxingDecoderHandler(); String content = handler.decode(imgPath); System.out.println("内容如下:"); System.out.println(content); } }
#和生成的相反
二维码生成
二维码解码
路上走来一步一个脚印,希望大家和我一起。
感谢读者!很喜欢你们给我的支持。如果支持,点个赞。
知识来源: https://github.com/zxing/zxing/wiki/Getting-Started-Developing
转载于:https://www.cnblogs.com/Alandre/p/3693162.html
相关资源:数据结构—成绩单生成器