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")); } }
最近下载更多
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日
x0000_00_00 LV1
2022年9月5日
Useradmin128 LV1
2022年8月29日
168668 LV1
2022年7月22日
最近浏览更多
kingoneyang LV13
2023年11月30日
lilihehe LV1
2023年10月19日
qingye LV1
2023年6月16日
zxh2023 LV1
2023年6月3日
zxsyaa LV1
2023年5月9日
liminshabi LV2
2023年4月14日
kkkukujiajia1
2023年2月20日
暂无贡献等级
2552655 LV1
2023年1月29日
June6666666666 LV1
2022年12月6日
leejunye
2022年11月21日
暂无贡献等级