Parsing two-dimensional code

Source: Internet
Author: User

Package www.ablanxue.com; 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.exception.decodingfailedexception;public Class QRCode {/** * parse QR code (qrcode) * @param imgpath Picture Path * @return * */public String DECODERQRC          Ode (String Imgpath) {//qrcode QR code picture file ImageFile = new files (imgpath);          BufferedImage bufimg = null;          String content = null;              try {bufimg = Imageio.read (ImageFile);              Qrcodedecoder decoder = new Qrcodedecoder ();           Content = new String (Decoder.decode (New Qrcodeimagebean (bufimg)), "Utf-8");              } catch (IOException e) {System.out.println ("Error:" + e.getmessage ());          E.printstacktrace ();           } catch (Decodingfailedexception DfE) {System.out.println ("Error:" + dfe.getmessage ());   Dfe.printstacktrace ();      } return content;          } public static void Main (string[] args) {String Imgpath = "K:/aaa.png";          QRCode handler = new QRCode ();        String Qrcon = Handler.decoderqrcode (Imgpath);          SYSTEM.OUT.PRINTLN ("Decoder success!!!");    System.out.println ("Two-dimensional code content:" + Qrcon); }}qrcodeimagebean.javapackage www.ablanxue.com; Import Java.awt.image.bufferedimage;import Jp.sourceforge.qrcode.data.qrcodeimage;public class QRCodeImageBean          Implements Qrcodeimage {BufferedImage bufimg;      Public Qrcodeimagebean (BufferedImage bufimg) {this.bufimg = bufimg;      } @Override public int getheight () {return bufimg.getheight ();      } @Override public int getPixel (int x, int y) {return Bufimg.getrgb (x, y);      } @Override public int getwidth () {return bufimg.getwidth (); }  }

  

Parsing two-dimensional code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.