Today we are going to learn about the usage of zxing, which only covers the Java SE section.
The study of Zxing
If you use zxing in a Java SE environment, you need to add dependencies in Maven's pom.xml:
<Dependency> <groupId>Com.google.zxing</groupId> <Artifactid>Javase</Artifactid> <version>3.3.0</version></Dependency>
First, according to the content to generate two-dimensional code
Public void Encodenoreturn (String content) { try { new File ("File/huhx.png"). Topath (); New Multiformatwriter (). Encode (content, Barcodeformat.qr_code, +); " PNG ", Path); Catch (Exception e) { e.printstacktrace (); }}
Second, according to the QR code to read the content
Public Static voidMain (string[] args) {File file=NewFile ("File/huhx.jpg"); BufferedImage BufferedImage=NULL; Try{bufferedimage=imageio.read (file); } Catch(IOException e) {e.printstacktrace (); } Luminancesource Source=NewBufferedimageluminancesource (BufferedImage); Binarybitmap Bitmap=NewBinarybitmap (NewHybridbinarizer (source)); Hashtable<decodehinttype, string> hints =NewHashtable<decodehinttype, string>(); Hints.put (Decodehinttype.character_set,"GBK"); Result result=NULL; Try{result=NewMultiformatreader (). Decode (bitmap, hints); } Catch(notfoundexception e) {e.printstacktrace (); } String URL=Result.gettext (); System.out.println (URL);}
Friendship Link
- Zxing's github address: https://zxing.github.io/zxing/
The use of Java three-party---->zxing Framework