BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); QRCodeReader reader = new QRCodeReader(); Result r = reader.decode(bitmap, hint); result = r.getText(); } catch (Exception e) { result = "读取错误"; } return result; } public static void main(String[] args) {...
QRCodeReader reader=new QRCodeReader(); Result result = reader.decode(binaryBitmap, null); //获取结果类 String text=result.getText(); //获取二维码内容 1. 2. 3. 4. 5. 6. 7. 8. ImageLuminanceSource实现 所以接下来我们要去创建一个类ImageLuminanceSource去继承LuminanceSource package test; impor...
import java.io.IOException; public class QRCodeReaderExample { public static void main(String[] args) { try { File file = new File('path/to/qrCodeImage.png'); BufferedImage image = ImageIO.read(file); BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLumin...
BufferedImage img=null;try{//构建二维码图片//QR_CODE 一种矩阵二维码BitMatrix bm = writer.encode(contents, BarcodeFormat.QR_CODE, width, height + 5, hint);int[] locationTopLeft =bm.getTopLeftOnBit();int[] locationBottomRight =bm.getBottomRightOnBit(); info.setBottomStart(newint[] { loca...
QRCodeReader reader = new QRCodeReader(); Result r = reader.decode(bitmap, hint); result = r.getText(); } catch (Exception e) { result = "读取错误"; } return result; }public static void main(String[] args) { String imgname = String.valueOf(System.currentTimeMillis()) + ".png...
hints.put(DecodeHintType.POSSIBLE_FORMATS,BarcodeFormat.QR_CODE); hints.put(DecodeHintType.TRY_HARDER,Boolean.TRUE); QRCodeReaderreader=newQRCodeReader(); Resultresult=null; try{ result=reader.decode(bMap,hints); HiLog.info(LABEL_LOG,"==>result:"+result.toString()); ...
import com.google.zxing.qrcode.QRCodeReader; import com.google.zxing.qrcode.QRCodeWriter; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.BufferedImage;
Result decode = qrCodeReader.decode(bitmap); System.out.println(decode); } 解析结果和我们刚才扫码结果一样: 我这里报错是因为生成图片的工具类(javase依赖的一个第三方包)获取JDK版本号报错了,我是open jDk9,版本号是9,但是包里面的,必须得是1.x才能被截取,这个错我也改不了,也懒得更换JDK版本,下面是...
QRCodeReader{publicstaticvoidmain(String[]args){try{File file=newFile("./QRCode.png");BufferedImage bufferedImage=ImageIO.read(file);LuminanceSource source=newBufferedImageLuminanceSource(bufferedImage);BinaryBitmap bitmap=newBinaryBitmap(newHybridBinarizer(source));Result result=newMultiFormatReader()...
publicstaticvoidparseQRCodeImage(StringfilePath,HashMaphints)throwsNotFoundException,IOException,ChecksumException,FormatException{QRCodeReaderqrCodeReader=newQRCodeReader();Filefile=newFile(filePath);BufferedImagebufferedImage=ImageIO.read(file);LuminanceSourceluminanceSource=newBufferedImageLuminanceSource(bufferedIma...