欢迎来到天天文库
浏览记录
ID:34723786
大小:111.68 KB
页数:22页
时间:2019-03-10
《java使用zxing包制作二维码》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、域名长度后缀删除日期删除类型33d.cc3cc2012/9/4Delete今天朋友问我一个二维码的东西,说实话我重来也没接触过,于是上网找了一下,和朋友分享一下...用qrcode.jar也能做,但是一看小日本的,于是马上闪过,听所zxing挺好用的,于是就去google下了架包用了这个感觉确实简单,重百度找到写完一个例子只用了,10来分钟........//www.hake.ccZxing是Google提供的关于条码(一维码、二维码)的解析工具,提供了二维码的生成与解析的方法,现在我简单介绍一下使用Java利用Zxing生成与解析二维码1、二维码的生成 1.
2、1将core.jar包加入到classpath下。 1.2二维码的生成需要借助MatrixToImageWriter类,该类是由Google提供的,可以将该类拷贝到源码中,这里我将该类的源码贴上,可以直接使用。[java]viewplaincopyprint?importcom.google.zxing.common.BitMatrix;importjavax.imageio.ImageIO;importjava.io.File;importjava.io.OutputStream;importjava.io.IOException;importjava.aw
3、t.image.BufferedImage;publicfinalclassMatrixToImageWriter{privatestaticfinalintBLACK=0xFF000000;privatestaticfinalintWHITE=0xFFFFFFFF;privateMatrixToImageWriter(){}publicstaticBufferedImagetoBufferedImage(BitMatrixmatrix){intwidth=matrix.getWidth();intheight=matrix.getHeight();Buffer
4、edImageimage=newBufferedImage(width,height,BufferedImage.TYPE_INT_RGB);for(intx=0;x5、toBufferedImage(matrix);if(!ImageIO.write(image,format,file)){thrownewIOException("Couldnotwriteanimageofformat"+format+"to"+file);}}publicstaticvoidwriteToStream(BitMatrixmatrix,Stringformat,OutputStreamstream)throwsIOException{BufferedImageimage=toBufferedImage(matrix);if(!ImageIO.6、write(image,format,stream)){thrownewIOException("Couldnotwriteanimageofformat"+format);}}}importcom.google.zxing.common.BitMatrix;importjavax.imageio.ImageIO;importjava.io.File;importjava.io.OutputStream;importjava.io.IOException;importjava.awt.image.BufferedImage;publicfinalclassMat7、rixToImageWriter{privatestaticfinalintBLACK=0xFF000000;privatestaticfinalintWHITE=0xFFFFFFFF;privateMatrixToImageWriter(){}publicstaticBufferedImagetoBufferedImage(BitMatrixmatrix){intwidth=matrix.getWidth();intheight=matrix.getHeight();BufferedImageimage=newBufferedImage(width,heigh8、t,BufferedIm
5、toBufferedImage(matrix);if(!ImageIO.write(image,format,file)){thrownewIOException("Couldnotwriteanimageofformat"+format+"to"+file);}}publicstaticvoidwriteToStream(BitMatrixmatrix,Stringformat,OutputStreamstream)throwsIOException{BufferedImageimage=toBufferedImage(matrix);if(!ImageIO.
6、write(image,format,stream)){thrownewIOException("Couldnotwriteanimageofformat"+format);}}}importcom.google.zxing.common.BitMatrix;importjavax.imageio.ImageIO;importjava.io.File;importjava.io.OutputStream;importjava.io.IOException;importjava.awt.image.BufferedImage;publicfinalclassMat
7、rixToImageWriter{privatestaticfinalintBLACK=0xFF000000;privatestaticfinalintWHITE=0xFFFFFFFF;privateMatrixToImageWriter(){}publicstaticBufferedImagetoBufferedImage(BitMatrixmatrix){intwidth=matrix.getWidth();intheight=matrix.getHeight();BufferedImageimage=newBufferedImage(width,heigh
8、t,BufferedIm
此文档下载收益归作者所有