找传奇、传世资源到传世资源站!

Java_实现_二维码生成与解析_实例_附完整源码_

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

java语言开发 二维码的生成与解析

Java_实现_二维码生成与解析_实例_附完整源码_ Java-第1张

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() {
		QRCodeDecoder decoder = new QRCodeDecoder();
		File imageFile = new File("D:\\Demo\\QRCode.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("Output Decoded Data is:" decodedData);
		} catch (DecodingFailedException dfe) {
			System.out.println("Error: "  dfe.getMessage());
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		QRCodeDecoderTest cRCodeDecoderTest=new QRCodeDecoderTest();
	}
}

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);
	}
}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复