Zxing QR code generation and Decoding

Source: Internet
Author: User

/*****/Package COM. google. zxing; import Java. io. file; import Java. io. ioexception; import Java. util. hashtable; import COM. google. zxing. common. bitmatrix; import COM. google. zxing. common. hybridbinarizer;/***** @ author hwy **/public class testendecode {/*****/Public testendecode () {// todo auto-generated constructor stub}/*** @ Param ARGs */public static void main (string [] ARGs) {// todo auto-generated method stub} // code public void encode () {try {string STR = "CN: Male; COP: Company; ZW: Title "; // string Path = "D: // hwy.png"; hashtable hints = new hashtable (); hints. put (encodehinttype. character_set, "GBK"); bitmatrix bytematrix; bytematrix = new multiformatwriter (). encode (STR, barcodeformat. qr_code, 200,200); file = new file (PATH); // writetofile (bytematrix, "PNG", file);} catch (exception e) {e. printstacktrace () ;}// decodes public void decode () {try {reader = new multiformatreader (); string imgpath = "D: // hwy.png "; file file = new file (imgpath); bufferedimage image; try {image = ImageIO. read (File); If (image = NULL) {system. out. println ("cocould not decode image");} luminancesource source = new bufferedimageluminancesource (image); binarybitmap bitmap = new binarybitmap (New hybridbinarizer (source); Result result; hashtable hints = new hashtable (); hints. put (decodehinttype. character_set, "GBK"); Result = new multiformatreader (). decode (bitmap, hints); string resultstr = result. gettext (); system. out. println (resultstr);} catch (ioexception IOE) {system. out. println (IOE. tostring ();} catch (readerexception re) {system. out. println (Re. tostring () ;}} catch (exception ex ){}}}

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.