在http://code.google.com/p/zxing/downloads/list下载zxing压缩包Zxing-1.5,
使用core与javase包
代码如下:
解析中文时注意修改 编码方式
package cn.wuhongbox.javaQR; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.Hashtable; import javax.imageio.ImageIO; import com.google.zxing.BarcodeFormat; import com.google.zxing.BinaryBitmap; import com.google.zxing.DecodeHintType; import com.google.zxing.LuminanceSource; import com.google.zxing.MultiFormatReader; import com.google.zxing.MultiFormatWriter; import com.google.zxing.Result; import com.google.zxing.client.j2se.BufferedImageLuminanceSource; import com.google.zxing.common.ByteMatrix; import com.google.zxing.common.HybridBinarizer; public class RQUtil { private static final int BLACK = 0xff000000; private static final int WHITE = 0xFFFFFFFF; /** * 生成二维码 * * @author wuhongbo * @param str * 内容 * @param height * 高度(px) * */ public static BufferedImage getRQ(String str, Integer height) { if (height == null || height < 100) { height = 200; } try { ByteMatrix byteMatrix = new MultiFormatWriter().encode(str, BarcodeFormat.QR_CODE, height, height); return toBufferedImage(byteMatrix); // 输出方式 // 网页 // ImageIO.write(image, "png", response.getOutputStream()); // 文件 // ImageIO.write(image, "png", file); } catch (Exception e) { e.printStackTrace(); } return null; } /** * 写到文件中 * * @author wuhongbo * @param str * @param height * @param file * @throws IOException */ public static void getRQwriteFile(String str, Integer height, File file) throws IOException { BufferedImage image = getRQ(str, height); ImageIO.write(image, "png", file); } /** * 转换成图片 * * @author wuhongbo * @param matrix * @return */ private static BufferedImage toBufferedImage(ByteMatrix matrix) { int width = matrix.getWidth(); int height = matrix.getHeight(); BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { image.setRGB(x, y, matrix.get(x, y) == 0 ? BLACK : WHITE); } } return image; } /** * 解码 各类型条码 */ public static String decodeRQ(File file) { BufferedImage image; try { if (file == null || file.exists() == false) { throw new Exception(" File not found:" + file.getPath()); } image = ImageIO.read(file); LuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); Result result; // 解码设置编码方式为:utf-8, Hashtable hints = new Hashtable(); 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) throws Exception { File file = new File("c://1.png"); RQUtil.getRQwriteFile("吴宏波中华人民共和国", 200, file); System.out.println("-----成生成功----"); System.out.println(); String s = RQUtil.decodeRQ(file); System.out.println("-----解析成功----"); System.out.println(s); } }
相关推荐
用labview调用外部库函数实现二维码的生成
Eclipse项目和AndroidStudio项目两种,详见:【安卓学习之代码学习】 二维码学习http://blog.csdn.net/ljb568838953/article/details/53286853 具有打开闪关灯功能,很不错! 存在的问题: 1.代码里面是2s滑动线上下...
zxing 实现二维码扫描 从相册获取二维码识别,部分机型有存储权限需自己做一下处理,闪光灯,以及集成了zxing的库,可自己直接引用生成等操作,
支持一维码EAN8, EAN13, UPCA, CODE39, CODE128, ITF,二维码QR_CODE的生成和读取。 本类库基于ZXing条形码库修改而来,主要的改动: * 取消支持部分条形码,较少库文件大小。 * 拆分为barcodelib.swc和barcodelib...
一个使用Google开源项目Zxing进行QR码解析的例程,我写了注释,编码方式为GBK,不过Zxing有个缺点必须离二维码远一些程序才能识别二维码
一个使用Google开源项目Zxing进行QR码解析的例程,不使用ViewFinderView作为扫描画面,扫面画面为纯xml编写,我写了注释,编码方式为GBK,不过Zxing有个缺点必须离二维码远一些程序才能识别二维码
writer.Format = BarcodeFormat.QR_CODE; writer.Options.Hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8");//编码问题 writer.Options.Hints.Add(EncodeHintType.ERROR_CORRECTION, ZXing.QrCode.Internal....
基于ZXing的二维码解码例程(源代码分享).rar 可以解QR码,PDF417码,DATAMatrix,等二维码。 需要相机支持自动对焦。 public static final AZTEC, public static final CODABAR, public static final CODE_39, ...
主要介绍了详解使用zxing库生成QR-Code二维码的相关资料,需要的朋友可以参考下
帮我们生成二维码的jar包,这是生成QRCode二维码的jar包,也是最近最常用的QR_Code二维码
基于Android Studio的 简化的ZXing库的 二维码识别程序 代码基本上来源于网络 稍有修改 所以分值最低了 1分而已
BitMatrix bitMatrix = new QRCodeWriter().encode(url, BarcodeFormat.QR_CODE, QR_WIDTH, QR_HEIGHT, hints); int[] pixels = new int[QR_WIDTH * QR_HEIGHT]; //下面这里按照二维码的算法,逐个生成二维码的...
个人学习二维码的全套资料,包括QR码ISO IEC 18004 2006及2015版全部标准,QR code 二维码基础入门教程之一、二、三;二维码(QR code)基本结构及生成原理;汉信码(Hanxin Code)与QR码(QR Code)的终极对决。以及...
flex4手机原生扩展应用,采用zxing开源代码针对Android手机实现条码扫描,能识别大部分条码。在flex手机项目中测试,完美兼容。
BitMatrix bitMatrix = new MultiFormatWriter().encode(contents, BarcodeFormat.QR_CODE, width, height); Path file = new File("D:/code/img.png").toPath(); MatrixToImageWriter.writeToPath...
C# 二维码生成工具源码下载(zxing.dll)
谷歌二维码扫描实例 需安装apk插件 ”Barcode ...// intent.putExtra("SCAN_MODE", "QR_CODE_MODE");//输入参数,(扫描类型,..二维码) 不定义默认扫描全部类型 startActivityForResult(intent, 0);//启动intent
ZXing一维码/二维码 使用文档 样例: System.IO.Stream stmYiWei = new System.IO.MemoryStream(); BitMatrix byteMatrix = new MultiFormatWriter().encode(sCode, BarcodeFormat.CODE_39, 230, 40); toBitmap...
ZXing (pronounced "zebra crossing") is an open-source, multi-format 1D/2D barcode image processing ...QR Code Data Matrix Aztec ('beta' quality) PDF 417 ('alpha' quality) http://code.google.com/p/zxing/