下载地址:
-
2010-01-28 11:01:00更多相关内容
-
Java实现二维码编码与解码
2022-03-31 13:45:05Java使用谷歌的zxing包实现二维码的编码与解码1、构建maven项目,导入对应依赖
这里引用谷歌的zxing包实现二维码的编码与解码,导入依赖如下所示<!-- 谷歌二维码 --> <dependency> <groupId>com.google.zxing</groupId> <artifactId>core</artifactId> <version>3.3.0</version> </dependency>
2、编写编码与解码方法
二维码生成工具类如下所示import java.awt.BasicStroke; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.Shape; import java.awt.geom.AffineTransform; import java.awt.geom.RoundRectangle2D; import java.awt.image.BufferedImage; import java.io.*; import java.util.Base64; import java.util.Hashtable; import javax.imageio.ImageIO; import com.google.zxing.*; import com.google.zxing.common.BitMatrix; import com.google.zxing.common.HybridBinarizer; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; public class QrCodeUtil { private static final String CHARSET = "utf-8"; private static final String IMAGE_SUFFIX = "JPG"; /** * 二维码尺寸 */ private static final int QRCODE_SIZE = 300; /** * LOGO宽度 */ private static final int WIDTH = 60; /** * LOGO高度 */ private static final int HEIGHT = 60; /** * 生成二维码图片, 可自定义容错率 * @param content 二维码内容 * @param logoPath logo图片路径 * @param needCompress 是否需要压缩 * @param level L-7% M-15% Q-25% H-30% 容错级别 * @return * @throws Exception */ private static BufferedImage createImage(String content, String logoPath, boolean needCompress, ErrorCorrectionLevel level) throws Exception { Hashtable hints = new Hashtable(); hints.put(EncodeHintType.ERROR_CORRECTION, level); hints.put(EncodeHintType.CHARACTER_SET, CHARSET); hints.put(EncodeHintType.MARGIN, 1); //生成二维码 BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, QRCODE_SIZE, QRCODE_SIZE, hints); int width = bitMatrix.getWidth(); int height = bitMatrix.getHeight(); BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); //构建图片 for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF); } } if (logoPath == null || "".equals(logoPath)) { return image; } // 插入图片,即中间显示的logo insertImage(image, logoPath, needCompress); return image; } /** * 生成二维码图片 * @param content 二维码文字内容 * @param logoPath logo图片路径 * @param needCompress 是否需要压缩 * @return * @throws Exception */ private static BufferedImage createImage(String content, String logoPath, boolean needCompress) throws Exception { return createImage(content, logoPath, needCompress, ErrorCorrectionLevel.H); } /** * 往二维码插入图片(logo) * @param source 二维码图片 * @param imgPath logo路径 * @param needCompress 是否需要压缩 * @throws Exception */ private static void insertImage(BufferedImage source, String imgPath, boolean needCompress) throws Exception { File file = new File(imgPath); if (!file.exists()) { System.err.println("" + imgPath + " 该文件不存在!"); return; } //获取源图片 Image image = ImageIO.read(new File(imgPath)); int width = image.getWidth(null); int height = image.getHeight(null); // 压缩LOGO if (needCompress) { width = width > WIDTH ? WIDTH : width; height = height > HEIGHT ? HEIGHT : height; image = image.getScaledInstance(width, height, Image.SCALE_SMOOTH); BufferedImage tag = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics g = tag.getGraphics(); // 绘制缩小后的图 g.drawImage(image, 0, 0, null); g.dispose(); } // 插入LOGO Graphics2D graph = source.createGraphics(); int x = (QRCODE_SIZE - width) / 2; int y = (QRCODE_SIZE - height) / 2; graph.drawImage(image, x, y, width, height, null); Shape shape = new RoundRectangle2D.Float(x, y, width, width, 6, 6); graph.setStroke(new BasicStroke(3f)); graph.draw(shape); graph.dispose(); } /** * 编码生成二维码图片,固化到硬盘 * @param content 二维码文字内容 * @param logoPath 插入的logo路径 * @param destPath 生成的二维码输出路径 * @param needCompress 是否需要压缩 * @param level 容错率 * @throws Exception */ public static void encode(String content, String logoPath, String destPath, boolean needCompress, ErrorCorrectionLevel level) throws Exception { mkdirs(destPath); ImageIO.write(createImage(content, logoPath, needCompress, level), IMAGE_SUFFIX, new File(destPath)); } /** * 编码生成二维码图片,固化到硬盘 * @param content 二维码文字内容 * @param logoPath logo图片路径 * @param destPath 生成的二维码输出路径 * @param needCompress 是否需要压缩 * @throws Exception */ public static void encode(String content, String logoPath, String destPath, boolean needCompress) throws Exception { mkdirs(destPath); ImageIO.write(createImage(content, logoPath, needCompress), IMAGE_SUFFIX, new File(destPath)); } /** * 编码生成二维码图片,固化到硬盘 * @param content 二维码文字内容 * @param logoPath logo图片路径 * @param destPath 生成的二维码输出路径 * @throws Exception */ public static void encode(String content, String logoPath, String destPath) throws Exception { encode(content, logoPath, destPath, false); } /** * 编码生成二维码图片,固化到硬盘 * @param content 二维码文字内容 * @param destPath 生成的二维码输出路径 * @throws Exception */ public static void encode(String content, String destPath) throws Exception { encode(content, null, destPath, false); } /** * 编码生成二维码图片,输出到流 * @param content 二维码文字内容 * @param logoPath logo图片路径 * @param output 输出流 * @param needCompress 是否需要压缩 * @throws Exception */ public static void encode(String content, String logoPath, OutputStream output, boolean needCompress) throws Exception { ImageIO.write(createImage(content, logoPath, needCompress), IMAGE_SUFFIX, output); } /** * 编码生成二维码图片,输出到流 * @param content 二维码文字内容 * @param output 输出流 * @throws Exception */ public static void encode(String content, OutputStream output) throws Exception { encode(content, null, output, false); } /** * 编码生成二维码图片,转化为base64字符串 * @param content 二维码文字内容 * @param imgPath logo图片路径 * @param needCompress 是否需要压缩 * @param level 容错率 * @param imageSuffix 生成的图片后缀 * @return * @throws Exception */ public static String encode(String content, String imgPath, boolean needCompress, ErrorCorrectionLevel level, String imageSuffix) throws Exception { imageSuffix = (imageSuffix == null || "".equals(imageSuffix)) ? IMAGE_SUFFIX : imageSuffix; BufferedImage image = createImage(content, imgPath, needCompress, level); ByteArrayOutputStream stream = new ByteArrayOutputStream(); ImageIO.write(image, imageSuffix, stream); return Base64.getEncoder().encodeToString(stream.toByteArray()); } /** * 编码生成二维码图片,直接返回图片对象 * @param content 二维码文字内容 * @param logoPath logo图片路径 * @param needCompress 是否需要压缩 * @return * @throws Exception */ public static BufferedImage encode(String content, String logoPath, boolean needCompress) throws Exception { return createImage(content, logoPath, needCompress); } /** * 二维码解码读取文字信息 * @param image 二维码图片 * @return * @throws Exception */ public static String decode(BufferedImage image) throws Exception { if (image == null) { return null; } BufferedImageLuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); Hashtable hints = new Hashtable(); //设置编码方式 hints.put(DecodeHintType.CHARACTER_SET, CHARSET); //优化精度,解决com.google.zxing.NotFoundException hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE); //开启PURE_BARCODE模式(复杂模式) hints.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE); Result result = new MultiFormatReader().decode(bitmap, hints); return result.getText(); } /** * 二维码解码读取文字信息 * @param file 二维码图片 * @return * @throws Exception */ public static String decode(File file) throws Exception { return decode(ImageIO.read(file)); } /** * 二维码解码读取文字信息 * @param base64Str 二维码图片base64格式字符串 * @return * @throws Exception */ public static String decode(String base64Str) throws Exception{ return decode(ImageIO.read(new ByteArrayInputStream(Base64.getDecoder().decode(base64Str)))); } /** * 创建文件夹 * @param destPath 文件夹路径 */ public static void mkdirs(String destPath) { File file = new File(destPath); // 当文件夹不存在时,mkdirs会自动创建多层目录,区别于mkdir.(mkdir如果父目录不存在则会抛出异常) if (!file.exists() && !file.isDirectory()) { file.mkdirs(); } } public static class BufferedImageLuminanceSource extends LuminanceSource { private final BufferedImage image; private final int left; private final int top; public BufferedImageLuminanceSource(BufferedImage image) { this(image, 0, 0, image.getWidth(), image.getHeight()); } public BufferedImageLuminanceSource(BufferedImage image, int left, int top, int width, int height) { super(width, height); int sourceWidth = image.getWidth(); int sourceHeight = image.getHeight(); if (left + width > sourceWidth || top + height > sourceHeight) { throw new IllegalArgumentException("Crop rectangle does not fit within image data."); } for (int y = top; y < top + height; y++) { for (int x = left; x < left + width; x++) { if ((image.getRGB(x, y) & 0xFF000000) == 0) { image.setRGB(x, y, 0xFFFFFFFF); // = white } } } this.image = new BufferedImage(sourceWidth, sourceHeight, BufferedImage.TYPE_BYTE_GRAY); this.image.getGraphics().drawImage(image, 0, 0, null); this.left = left; this.top = top; } @Override public byte[] getRow(int y, byte[] row) { if (y < 0 || y >= getHeight()) { throw new IllegalArgumentException("Requested row is outside the image: " + y); } int width = getWidth(); if (row == null || row.length < width) { row = new byte[width]; } image.getRaster().getDataElements(left, top + y, width, 1, row); return row; } @Override public byte[] getMatrix() { int width = getWidth(); int height = getHeight(); int area = width * height; byte[] matrix = new byte[area]; image.getRaster().getDataElements(left, top, width, height, matrix); return matrix; } @Override public boolean isCropSupported() { return true; } @Override public LuminanceSource crop(int left, int top, int width, int height) { return new BufferedImageLuminanceSource(image, this.left + left, this.top + top, width, height); } @Override public boolean isRotateSupported() { return true; } @Override public LuminanceSource rotateCounterClockwise() { int sourceWidth = image.getWidth(); int sourceHeight = image.getHeight(); AffineTransform transform = new AffineTransform(0.0, -1.0, 1.0, 0.0, 0.0, sourceWidth); BufferedImage rotatedImage = new BufferedImage(sourceHeight, sourceWidth, BufferedImage.TYPE_BYTE_GRAY); Graphics2D g = rotatedImage.createGraphics(); g.drawImage(image, transform, null); g.dispose(); int width = getWidth(); return new BufferedImageLuminanceSource(rotatedImage, top, sourceWidth - (left + width), getHeight(), width); } } }
主要方法功能描述如下:
- createImage():生成二维码图片
createImage()重载了两个方法,其中 createImage(String content, String logoPath, boolean needCompress, ErrorCorrectionLevel level)方法可通过level参数调节二维码容错率;createImage(String content, String logoPath, boolean needCompress)方法使用固定的容错率:ErrorCorrectionLevel.H。
- insertImage():往二维码插入图片(logo),可以调用此方法在二维码中间位置插入一个logo
- encode():进行二维码编码
此方法重载了几个方法返回不同的结果,如:直接生成二维码图片固化到硬盘;生成BASE64字符串返回;直接返回BufferedImage图片对象。 - decode():对二维码进行解码,获取文字内容
3、编写测试代码
编写测试代码进行不同返回对象的测试,测试代码如下所示public static void main(String[] args) throws Exception { // 存放在二维码中的内容 String text = "使用 com.google.zxing 依赖生成二维码图片,encode()方法生成二维码图片,decode()方法将二维码解码获取文字内容\n" ; // 嵌入二维码的图片(logo)路径 String imgPath = "E:/templates/0.jpg"; // 生成的二维码的路径及名称 String destPath = "E:/templates/qrcode/1.jpg"; // 生成的二维码的路径及名称 String destPath1 = "E:/templates/qrcode/2.jpg"; //生成不带logo的二维码 QrCodeUtil.encode(text, null, destPath, true, ErrorCorrectionLevel.L); //生成带logo的二维码 QrCodeUtil.encode(text, imgPath, destPath1, true, ErrorCorrectionLevel.L); // 解析二维码 String str = QrCodeUtil.decode(new File(destPath1)); // 打印出解析出的内容 System.out.println(str); //图片生成base64字符串 String base64 = QrCodeUtil.encode(text, imgPath, true, ErrorCorrectionLevel.L, "png"); System.out.println("\nbase64字符串:" + base64); System.out.println("\n二维码解码内容:" + QrCodeUtil.decode(base64)); }
4、可能遇到的问题
- 解析二维码报错com.google.zxing.NotFoundException
原因:二维码所有的bit都是0,生成二维码时白色像素使用透明色填充。在显示时因为背景是白色,所以看上去和用手机扫都没有问题,但是在代码识别的时候会把透明色识别为黑色,这样就导致整个二维码图片全是黑色像素,抛出com.google.zxing.NotFoundException异常。
解决方案:优化精度,解码时配置参数
//优化精度,解决com.google.zxing.NotFoundException hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE); //开启PURE_BARCODE模式(复杂模式) hints.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE);
- 扫码时由于文字太多无法识别
解决方案: 调整ErrorCorrectionLevel 参数,适当调整容错率(7%~30%)。
对应四个级别:
ErrorCorrectionLevel.L (7%)
ErrorCorrectionLevel.M (15%)
ErrorCorrectionLevel.Q (25%)
ErrorCorrectionLevel.H (30%)
容错率越高,二维码的有效像素点越多。
-
QRCode.jar包和二维码编码与解码的实现
2015-09-17 18:47:40QRCode.jar包和二维码编码与解码的实现 -
QRCode 二维码编码解码标准附录.pdf
2021-02-10 17:18:05QRCode 二维码编码解码标准附录.pdf -
Java版二维码编码与解码
2013-06-06 18:03:04完整二维码编码和解码包,本人收集整合成一个包,并附带完整的工具方法和运行例子可直接使用到手机客户端或应用。 解压后,引用TwoDimCode.jar包,运行使用TwoDimCode.java 绝对超值,下载看看吧! -
java的二维码编码与解码
2013-11-16 14:58:24很简单的一个java二维码编码与解码的说明文档,只需要你创建一个java程序,将代码复制过去就能用,新手也能看明白哦 -
QRCode二维码编码解码工具(C++)
2016-12-07 23:59:19完整的能够实现将文本文件编码为二维码图片或将二维码图片解码为文本的小工具。 基于zxing的解码库,libqrcode的编码库,开源可根据需求修改。 vs工程、c++编写,命令行下输入参数即可实现转化,移植性强。 支持中文... -
二维码编码解码源代码qr实.rar
2019-08-22 10:38:54软件的开发平台是.net 开发,开发环境是 vs2010 实现功能是 qr二维码编码 解码 -
最新二维码编码与解码平台(PDF417/QrCode/DataMatrix)
2012-11-01 23:19:552012年最新二维码编码和解码程序套件,是开发二维条码生成和自动识别应用参考实例。自动识别PDF417、QRCODE、DataMatrix和HanXin条码图形,同时又能将文本、图像、声音和指纹混合编码,生成二维条码。二维码种类包括... -
二维码编码与解码类库ThoughtWorks.QRCode
2017-08-25 09:44:00支持二维码编码(生成)和解码(识别) 似乎不支持中文,不过可以自己修改源代码的编码格式来支持中文 我比较关注二维码识别功能,所以比较详细的测试了 1、非居中、带LOGO、彩色二维码均能识别 2、有大量干扰...官方地址:https://www.codeproject.com/Articles/20574/Open-Source-QRCode-Library
有源代码和示例程序
支持二维码编码(生成)和解码(识别)
似乎不支持中文,不过可以自己修改源代码的编码格式来支持中文
我比较关注二维码识别功能,所以比较详细的测试了
1、非居中、带LOGO、彩色二维码均能识别
2、有大量干扰的情况下识别失败
3、将二维码旋转到15度左右仍能识别
修改源代码之后支持中文了
下载地址:https://pan.baidu.com/s/1hrQ9nCC
最后的最后,要让你们失望了,无法解码微信和支付宝二维码,这2种二维码都是自己定义的编码格式,不是国际标准格式。
转载于:https://www.cnblogs.com/jjg0519/p/7426534.html
-
C sharp的二维码编码解码程序
2018-09-10 10:12:07C sharp的二维码编码解码程序,QRCode支持纠错码,有Windows及Windows Mobile的完整工程 -
C# 二维码编码和解码代码实现不调用控件
2014-09-22 08:52:35C#写的二维码编码类和二维码解码类,不调用任何控件,方便翻译成任何语言,可在任意平台上运行。 内有说明文档,说明怎样设置和调用,使用非常的方便,编码一个类,解码一个类,不像网上搜索的那些各种复杂不好用,... -
二维码的编解码标准2(dm)
2020-05-27 16:42:20Data Matrix is a two-dimensional matrix symbology which is made up of nominally square modules arranged within a perimeter finder pattern. Though primarily shown and described in this document as a ... -
C#二维码编码和解码
2011-07-20 14:46:43在csdn下载的qrcode,在vs2010下编译总是有错,于是我重新封装了一下,win7+vs2010下测试通过。生成的二维码图片使用iphone4的识别软件准确无误,放上源代码,大家一起研究一下。 -
C#二维码编码解码器源码
2017-04-27 10:56:30C#二维码编码解码器源码 -
Java利用QRCode.jar包实现二维码编码与解码
2019-10-05 19:48:37QRcode是日本人94年开发...qrcode需要设置一个版本号,这个版本号代表你生成的二维码的像素的大小。版本1是21*21的,版本号每增加1,边长增加4。也就是说版本7的大小是45 * 45的。版本号最大值是40。另外,版本7的编...QRcode是日本人94年开发出来的。首先去QRCode的官网http://swetake.com/qrcode/java/qr_java.html,把要用的jar包下下来,导入到项目里去。qrcode需要设置一个版本号,这个版本号代表你生成的二维码的像素的大小。版本1是21*21的,版本号每增加1,边长增加4。也就是说版本7的大小是45 * 45的。版本号最大值是40。另外,版本7的编码的字节数如果超过了119,那么将无法编码
1.二维码图片类实现
package com.reyo.code; import java.awt.image.BufferedImage; import jp.sourceforge.qrcode.data.QRCodeImage; public class TwoDimensionCodeImage implements QRCodeImage { BufferedImage bufImg; public TwoDimensionCodeImage(BufferedImage bufImg) { this.bufImg = bufImg; } @Override public int getHeight() { return bufImg.getHeight(); } @Override public int getPixel(int x, int y) { return bufImg.getRGB(x, y); } @Override public int getWidth() { return bufImg.getWidth(); } }
2.二维码编解码类实现
package com.reyo.code; import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import javax.imageio.ImageIO; import jp.sourceforge.qrcode.QRCodeDecoder; import jp.sourceforge.qrcode.exception.DecodingFailedException; import com.swetake.util.Qrcode; public class TwoDimensionCode { /** * 生成二维码(QRCode)图片 * @param content 存储内容 * @param imgPath 图片路径 */ public void encoderQRCode(String content, String imgPath) { this.encoderQRCode(content, imgPath, "png", 7); } /** * 生成二维码(QRCode)图片 * @param content 存储内容 * @param output 输出流 */ public void encoderQRCode(String content, OutputStream output) { this.encoderQRCode(content, output, "png", 7); } /** * 生成二维码(QRCode)图片 * @param content 存储内容 * @param imgPath 图片路径 * @param imgType 图片类型 */ public void encoderQRCode(String content, String imgPath, String imgType) { this.encoderQRCode(content, imgPath, imgType, 7); } /** * 生成二维码(QRCode)图片 * @param content 存储内容 * @param output 输出流 * @param imgType 图片类型 */ public void encoderQRCode(String content, OutputStream output, String imgType) { this.encoderQRCode(content, output, imgType, 10); } /** * 生成二维码(QRCode)图片 * @param content 存储内容 * @param imgPath 图片路径 * @param imgType 图片类型 * @param size 二维码尺寸 */ public void encoderQRCode(String content, String imgPath, String imgType, int size) { try { BufferedImage bufImg = this.qRCodeCommon(content, imgType, size); File imgFile = new File(imgPath); // 生成二维码QRCode图片 ImageIO.write(bufImg, imgType, imgFile); } catch (Exception e) { e.printStackTrace(); } } /** * 生成二维码(QRCode)图片 * @param content 存储内容 * @param output 输出流 * @param imgType 图片类型 * @param size 二维码尺寸 */ public void encoderQRCode(String content, OutputStream output, String imgType, int size) { try { BufferedImage bufImg = this.qRCodeCommon(content, imgType, size); // 生成二维码QRCode图片 ImageIO.write(bufImg, imgType, output); } catch (Exception e) { e.printStackTrace(); } } /** * 生成二维码(QRCode)图片的公共方法 * @param content 存储内容 * @param imgType 图片类型 * @param size 二维码尺寸 * @return */ private BufferedImage qRCodeCommon(String content, String imgType, int size) { BufferedImage bufImg = null; try { Qrcode qrcodeHandler = new Qrcode(); // 设置二维码排错率,可选L(7%)、M(15%)、Q(25%)、H(30%),排错率越高可存储的信息越少,但对二维码清晰度的要求越小 qrcodeHandler.setQrcodeErrorCorrect('M'); qrcodeHandler.setQrcodeEncodeMode('B'); // 设置设置二维码尺寸,取值范围1-40,值越大尺寸越大,可存储的信息越大 qrcodeHandler.setQrcodeVersion(size); // 获得内容的字节数组,设置编码格式 byte[] contentBytes = content.getBytes("utf-8"); // 图片尺寸 int imgSize = 67 + 12 * (size - 1); bufImg = new BufferedImage(imgSize, imgSize, BufferedImage.TYPE_INT_RGB); Graphics2D gs = bufImg.createGraphics(); // 设置背景颜色 gs.setBackground(Color.WHITE); gs.clearRect(0, 0, imgSize, imgSize); // 设定图像颜色> BLACK gs.setColor(Color.BLACK); // 设置偏移量,不设置可能导致解析出错 int pixoff = 2; // 输出内容> 二维码 if (contentBytes.length > 0 && contentBytes.length < 800) { boolean[][] codeOut = qrcodeHandler.calQrcode(contentBytes); for (int i = 0; i < codeOut.length; i++) { for (int j = 0; j < codeOut.length; j++) { if (codeOut[j][i]) { gs.fillRect(j * 3 + pixoff, i * 3 + pixoff, 3, 3); } } } } else { throw new Exception("QRCode content bytes length = " + contentBytes.length + " not in [0, 800]."); } gs.dispose(); bufImg.flush(); } catch (Exception e) { e.printStackTrace(); } return bufImg; } /** * 解析二维码(QRCode) * @param imgPath 图片路径 * @return */ public String decoderQRCode(String imgPath) { // QRCode 二维码图片的文件 File imageFile = new File(imgPath); BufferedImage bufImg = null; String content = null; try { bufImg = ImageIO.read(imageFile); QRCodeDecoder decoder = new QRCodeDecoder(); content = new String(decoder.decode(new TwoDimensionCodeImage(bufImg)), "utf-8"); } catch (IOException e) { System.out.println("Error: " + e.getMessage()); e.printStackTrace(); } catch (DecodingFailedException dfe) { System.out.println("Error: " + dfe.getMessage()); dfe.printStackTrace(); } return content; } /** * 解析二维码(QRCode) * @param input 输入流 * @return */ public String decoderQRCode(InputStream input) { BufferedImage bufImg = null; String content = null; try { bufImg = ImageIO.read(input); QRCodeDecoder decoder = new QRCodeDecoder(); content = new String(decoder.decode(new TwoDimensionCodeImage(bufImg)), "utf-8"); } catch (IOException e) { System.out.println("Error: " + e.getMessage()); e.printStackTrace(); } catch (DecodingFailedException dfe) { System.out.println("Error: " + dfe.getMessage()); dfe.printStackTrace(); } return content; } public static void main(String[] args) { String imgPath = "C:\\zhaochao.png"; String encoderContent =""; for(int i=0;i<40;i++) encoderContent+="锐洋智能"; TwoDimensionCode handler = new TwoDimensionCode(); handler.encoderQRCode(encoderContent, imgPath, "png",10); System.out.println("=============编码成功!图片为于:"+imgPath+"==============="); String decoderContent = handler.decoderQRCode(imgPath); System.out.println("============解析结果如下:==============="); System.out.println(decoderContent); System.out.println("=========解码成功==========="); } }
转载于:https://www.cnblogs.com/interdrp/p/7043738.html
-
条形码和二维码编码和解码
2015-07-28 09:56:00条形码和二维码编码和解码(通过引用zxing) 条形码:编码方式:EAN_13编码;EAN_8编码;Code39编码 二维码:编码方式:QRCode编码 -
qrcode-desktop:基于 ZXing 和 Java 的桌面二维码编码器解码器 GUI
2021-05-31 10:59:17它还可以从屏幕截图中解码二维码。 截图 建造 在构建 qrcode-desktop 之前,您的系统上必须安装以下软件包: jdk 行家 打开终端并切换到qrcode-desktop目录。 键入以下命令以构建 jar 存档: mvn package 如果... -
二维码编码/解码器
2013-03-04 13:23:20一个能将网址编码成二维码或将二维码解码成网址的小工具。 -
.net二维码编码解码器源码
2017-08-31 09:55:42.net二维码编码解码器源码 -
.Net C#环境 二维码编码/解码组件
2015-08-23 00:52:39在C#程序中生成和读取二维码主要有ThoughtWorks.QRCode和Zxing两种解决方案。个人体验认为,ThoughtWorks.QRCode的编码功能完善,...并对二维码的适用范围进行了扩展,可完成字符串、byte[]数据与二维码图像之间的转换 -
QR二维码编码及解码程序
2013-12-26 17:56:16这是QR二维码的编码和解码程序,两个工程放在同一个工作空间中,便于大家学习,调试程序,已经在VC6.0下成功编译,运行正常。 -
Java实现二维码QRCode的编码和解码与示例解析
2020-09-01 21:40:25本文主要介绍Java实现二维码QRCode的编码和解码,这里给大家一个小示例以便理解,有需要的小伙伴可以参考下 -
二维码编码解码器源码20130905
2013-09-05 13:45:41二维码编码解码器源码 本源码实现可以在C#中使用的1D/2D编码解码器。条形码的应用已经非常普遍,几乎所有超市里面的商品上面都印有条形码;二维码也开始应用到很多场合,如火车票有二维码识别、网易的首页有二维码... -
二维码编码解码库ZBar64.rar
2021-10-20 16:54:59二维码编码解码库zbar64,可在VS2019正常使用,普通zbar用不了是因为不是64位的 -
Qr 二维码 编码及解码
2011-08-29 14:41:32Qr 二维码 编码及解码 完整Eclipse项目,jdk1.5