package cn.edu.zafu;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import jp.sourceforge.qrcode.QRCodeDecoder;
import jp.sourceforge.qrcode.data.QRCodeImage;
import jp.sourceforge.qrcode.exception.DecodingFailedException;
public class Decode {
public static class QRImage implements QRCodeImage {
BufferedImage bufImg;
public QRImage(BufferedImage bufImg) {
this.bufImg = bufImg;
}
public int getWidth() {
return bufImg.getWidth();
}
public int getHeight() {
return bufImg.getHeight();
}
public int getPixel(int x, int y) {
return bufImg.getRGB(x, y);
}
}
public static String decoderQRCode(String imgPath) {
// QRCode 二维码图片的文件
File imageFile = new File(imgPath);
BufferedImage bufImg = null;
String decodedData = null;
try {
bufImg = ImageIO.read(imageFile);
QRCodeDecoder decoder = new QRCodeDecoder();
decodedData = new String(decoder.decode(new QRImage(bufImg)));
} catch (IOException e) {
System.out.println("Error: " + e.getMessage());
e.printStackTrace();
} catch (DecodingFailedException dfe) {
System.out.println("Error: " + dfe.getMessage());
dfe.printStackTrace();
}
return decodedData;
}
public static void main(String[] args) {
System.out.println(decoderQRCode("1.png"));
}
}
最近下载更多
zkjzkj123456 LV1
5月26日
訾政阳 LV1
2024年6月13日
zbjmml LV1
2024年5月7日
lilihehe LV1
2023年10月19日
zxsyaa LV1
2023年5月9日
2552655 LV1
2023年1月29日
June6666666666 LV1
2022年12月6日
微信网友_6224558473859072 LV1
2022年11月18日
OneTea LV1
2022年9月29日
老舰了你 LV1
2022年9月24日
最近浏览更多
zkjzkj123456 LV1
5月26日
微信网友_7351677866266624
1月22日
暂无贡献等级
zzkcll LV1
1月22日
edpwyg LV14
2024年7月22日
訾政阳 LV1
2024年6月13日
Protein
2024年5月27日
暂无贡献等级
zbjmml LV1
2024年5月7日
kingoneyang LV13
2023年11月30日
lilihehe LV1
2023年10月19日
qingye LV1
2023年6月16日

