日本人写的解码与编码实现Sourceforge.jp与swetake.com
这里把它们merge到一个jar文件里。
编码测试:
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import com.swetake.util.Qrcode;
public class QRCodeEncoderTest {
public static void main(String[] args) throws Exception {
Qrcode qrcode=new Qrcode();
qrcode.setQrcodeErrorCorrect('M');
qrcode.setQrcodeEncodeMode('B');
qrcode.setQrcodeVersion(7);
String testString = "_-+^%$#@!~`=&)*(";
byte[] d =testString.getBytes("GBK");
BufferedImage bi = new BufferedImage(139, 139, BufferedImage.TYPE_INT_RGB);
// createGraphics
Graphics2D g = bi.createGraphics();
// set background
g.setBackground(Color.WHITE);
g.clearRect(0, 0, 139, 139);
g.setColor(Color.BLACK);
if (d.length>0 && d.length <123){
boolean[][] b = qrcode.calQrcode(d);
for (int i=0;i<b.length;i++){
for (int j=0;j<b.length;j++){
if (b[j][i]) {
g.fillRect(j*3+2,i*3+2,3,3);
}
}
}
}
g.dispose();
bi.flush();
String FilePath="TestQRCode.png";
File f = new File(FilePath);
ImageIO.write(bi, "png", f);
System.out.println("doned!");
}
}
解码测试:
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import javax.imageio.ImageIO;
import jp.sourceforge.qrcode.QRCodeDecoder;
import jp.sourceforge.qrcode.data.QRCodeImage;
import jp.sourceforge.qrcode.exception.DecodingFailedException;
public class QRCodeDecoderTest {
public QRCodeDecoderTest() {
}
public static void main(String[] args) {
QRCodeDecoder decoder = new QRCodeDecoder();
File imageFile = new File("TestQRCode.png");
BufferedImage image = null;
try {
image = ImageIO.read(imageFile);
} catch (IOException e) {
System.out.println("Error: "+ e.getMessage());
}
try {
String decodedData = new String(decoder.decode(new J2SEImage(image)),"GBK");
System.out.println(decodedData);
} catch (DecodingFailedException dfe) {
System.out.println("Error: " + dfe.getMessage());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
class J2SEImage implements QRCodeImage {
BufferedImage image;
public J2SEImage(BufferedImage image) {
this.image = image;
}
public int getWidth() {
return image.getWidth();
}
public int getHeight() {
return image.getHeight();
}
public int getPixel(int x, int y) {
return image.getRGB(x, y);
}
}
分享到:
相关推荐
基于opencv+zbar开源库摄像头自动扫一维码、二维码,可开启可视窗口,工程中有完整的对ini的读写操作
#二维码(QRcode)生成算法 C语言/C++ 源码 1. 根据输入字符串识别编码模式; 2. 根据输入字符串长度选择合适的QRcode版本; 3. 将编码转换为二进制位流表示为数据码字; 4. 使用多项式生成纠错码; 5. 将数据码和...
生成的QR code的网址是:http://swetake.com/qr/; 支持的原因版本还比较丰富,支持QRcode Perl的CGI和PHP脚本的版本,Ruby和java都有对应的支持类库等源代码,用起来还是很方便的;
这样就能通过test参数生成相应的二维码了 // 引入库文件 include __DIR__ . '/phpqrcode.php'; $errorCorrectionLevel = 'L'; $matrixPointSize = 9; $text = isset($_GET['text']) ? $_GET['text'] : ''; // php...
最近做一个项目,要用二维码,要求.net2.0,而且二维码图片拉伸之后,领导说好像有点模糊...源码,C# QRCode带LOGO二维码,可自定义二维码图片大小,不影响图片清晰度。 .net2.0。要引用“ThoughtWorks.QRCode.dll”哦
Java QRCode二维码生成与识别,开放源代码,多种生成方式.支持汉字存储与解析。
原理:先使用phpqrcode生成标准的二维码保存到图片文件,然后使用gd函数读取二维码图片和logo文件,将logo图片嵌入到二维码中保存输出带logo的二维码 如果不需要嵌入logo,只需要删除后面的代码即可。
微信扫码引擎是一款基于开源引擎ZXing,并高度优化和深度改造的高性能轻量二维码识别器。 import cv2 detector = cv2.wechat_qrcode_WeChatQRCode("detect.prototxt", "detect.caffemodel", "sr.prototxt", "sr....
原原二维码识别1.0 ●基于微信wechat_qrcode开源opencv微信二维码扫码识别插件; ●本地二维码图片识别; ●网络二维码图片识别; ●网络二维码图片识别接口: ...●支持高并发、多线程识别。返回识别后的字符串;...
完整的能够实现将文本文件编码为二维码图片或将二维码图片解码为文本的小工具。 基于zxing的解码库,libqrcode的编码库,开源可根据需求修改。 vs工程、c++编写,命令行下输入参数即可实现转化,移植性强。 支持中文...
生成二维码和生成下载链接的关于qrcode第三方库的使用,可参照
C语言生成二维码库(嵌入式设备)源码
qrcode的二维码源码,编译后可以直接使用,解码工程需要和opencv做图像处理待上传,源码使用的时vs编译的
当时想到了一些优秀的前端开源库 jquery-qrcode 和 node-qrcode,由于小程序中没有DOM的概念,这些库在小程序中并不适用。 所以,针对微信小程序的特点,封装了 weapp.qrcode.js ,用于在小程序中快速生成二维码 ...
来自开源的QRCODE二维码程序,可以将字符串内容转化成二维码图片
phpqrcode项目介绍开源的phpqrcode生成二维码使用说明案例一:demo.php案例二:phpqrcode / index.php参与贡献phpqrcode(官网)[ ]
12月10日起,全国铁路系统火车票将实现从5.0版本到5.2版本的...下面是一个开源的Open Source QRCode Library:http://www.codeproject.com/KB/cs/qrcode.aspx 下载下来不支持中文,还有手机上用起来报错,解决方法见 ...
读取和摄像头读取的是Open Source QR Code Library,官方网站为:http://qrcode.sourceforge.jp/ ,读取QR Code的所有代码,可以直接读取图片直接进行解析,也可以正常支持中文等,其中有个jmfexample就能实现通过...
通过QRCode开源代码实现的二维码生成工具,在QT环境下实现。