Package com.ust.map;
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 Qrcodedecoderhandler {
/** * decode QR code * @param imgpath * @return string */public string Decoderqrcode (String imgpath) {//qrcode QR code picture file Fil E 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 J2seimage (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;} /** * @param args the command line arguments */public static void main (string[] args) {Qrcodedecoderhandler handler = New Qrcodedecoderhandler (); String Imgpath = "e://ido//Two-dimensional code//yizhicheng.png"; String decodercontent = Handler.decoderqrcode (Imgpath); System.out.println ("Parse the result as follows:"); System.out.println (decodercontent); SyStem.out.println ("========decoder success!!!");} Class J2seimage implements Qrcodeimage {BufferedImage bufimg; Public J2seimage (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); }}
}
How Java parses two-dimensional code