首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

Java生成二维码或1维条形码(待续 未完)

2012-07-24 
Java生成二维码或一维条形码(待续 未完)Java生成二维码或一维条形码(待续)?前段时间用了“我查查”的软件 ?

Java生成二维码或一维条形码(待续 未完)

Java生成二维码或一维条形码(待续)

?

前段时间用了“我查查”的软件

?

手机可以直接扫描条码,所以自己也想来试试

?

需要研究的如下

1、一维码的 读取、生成

2、二维码的 读取、生成

3、使用摄像头 直接读取条码(待研究)

4、使用条码枪,利用dll读取条码(待研究)

?

下面是收集的相关资料

QR Code二维条形码的生成和读取解析和摄像头的读取? http://www.i5a6.com/?p=556
Java实现二维码QRCode的编码和解码? http://www.2cto.com/kf/201108/98471.html

条形码处理类库 ZXing? http://www.oschina.net/p/zxing

相关jar 包下载 http://swetake.com/qr/

?

?

代码包结构如下

├─一维条码
│????? Read.java
│????? Write.java

└─二维条码
??????? QRCodeDecoderHandler.java
??????? QRCodeEncoderHandler.java
??????? Read2.java
??????? TxmWrite.java
??????? Write2.java

?

jar包含

??? jbarcode-0.2.8.jar
??? qrcode.jar
??? Qrcode_swetake.jar
??? zxing1.3_core.jar
??? zxing1.3_javase.jar

?

?

?

?

package 二维条码;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.net.URL;

import javax.imageio.ImageIO;

import jp.sourceforge.qrcode.QRCodeDecoder;
import jp.sourceforge.qrcode.data.QRCodeImage;
import jp.sourceforge.qrcode.util.ContentConverter;

import com.swetake.util.Qrcode;

//二维条形码

public class TxmWrite
{
??? public static void main(String[] args) throws Exception
??? {
??????? TxmWrite test = new TxmWrite();
??????? test.creatTxm("676317283718啊好的乖哈苏德");
??????? test.readTxm("TxmQRCode.png");
??? }

??? /**
???? * 创建二维条形码
???? *
???? * @param param
???? *??????????? 比如身份证号码
???? * @throws Exception
???? */
??? public void creatTxm(String param) throws Exception
??? {
??????? Qrcode qrcode = new Qrcode();
??????? qrcode.setQrcodeErrorCorrect('M');
??????? qrcode.setQrcodeEncodeMode('B');
??????? qrcode.setQrcodeVersion(7);

??????? byte[] bstr = param.getBytes("UTF-8");
??????? BufferedImage bi = new BufferedImage(139, 139, BufferedImage.TYPE_INT_RGB);
??????? Graphics2D g = bi.createGraphics();
??????? g.setBackground(Color.WHITE); // 背景颜色
??????? g.clearRect(0, 0, 139, 139);
??????? g.setColor(Color.BLACK); // 条码颜色
??????? if (bstr.length > 0 && bstr.length < 123)
??????? {
??????????? boolean[][] b = qrcode.calQrcode(bstr);
??????????? 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 = "TxmQRCode.png";
??????? File f = new File(FilePath);
??????? ImageIO.write(bi, "png", f);
??? }

??? /**
???? * 解析二维条形码
???? *
???? * @param path
???? *??????????? 条形码图片的路径
???? * @throws Exception
???? */
??? public void readTxm(String path) throws Exception
??? {
??????? QRCodeDecoder decoder = new QRCodeDecoder();
??????? BufferedImage image = null;
??????? if (path.startsWith("http://"))
??????? {
??????????? image = ImageIO.read(new URL(path));
??????? } else
??????? {
??????????? image = ImageIO.read(new File(path));
??????? }
??????? String decodedString = new String(decoder.decode(new J2SEImage1(image)), "UTF-8");
??????? decodedString = ContentConverter.convert(decodedString);
??????? System.out.println("条码内容:" + decodedString);
??? }

}

class J2SEImage1 implements QRCodeImage
{
??? BufferedImage image;

??? public J2SEImage1(BufferedImage source)
??? {
??????? this.image = source;
??? }

??? public int getWidth()
??? {
??????? return image.getWidth();
??? }

??? public int getHeight()
??? {
??????? return image.getHeight();
??? }

??? public int getPixel(int x, int y)
??? {
??????? return image.getRGB(x, y);

??? }
}

?

?

热点排行