Package liupeng; import Java. io. file; import Org. JSON. jsonexception; import Org. JSON. jsonobject; public class test {/*** Description: QR code generation * @ author liupeng * @ Param ARGs * @ throws jsonexception */public static void main (string [] ARGs) throws jsonexception {jsonobject OBJ = new jsonobject (); obj. put ("name", "liupeng"); obj. put ("Age", 22); obj. put ("school", "[Yancheng Normal University] Emy of Information Science and Technology-> Software Engineering"); // string tomcatroot = httpreq Uest. getsession (). getservletcontext (). getrealpath ("/sealandsignimages"); // string Path = qrcodeoperator. makeqrcode (tomcatroot, "Liu Peng's QR code", obj. tostring (); string Path = qrcodeoperator. makeqrcode ("F:" + file. separator, "Liu Peng's QR code", obj. tostring (); If (path! = "") {System. out. println ("the QR code content is:" + obj. tostring () ;}} package liupeng; import Java. AWT. image. bufferedimage; import Java. io. file; import Java. util. hashmap; import Java. util. map; import javax. imageIO. imageIO; import javax. servlet. HTTP. httpservletrequest; import COM. google. zxing. barcodeformat; import COM. google. zxing. binarizer; import COM. google. zxing. binarybitmap; import COM. google. zxing. encodehinttype; import Com. google. zxing. luminancesource; import COM. google. zxing. multiformatreader; import COM. google. zxing. multiformatwriter; import COM. google. zxing. result; import COM. google. zxing. common. bitmatrix; import COM. google. zxing. common. hybridbinarizer; public class qrcodeoperator {/*** generate a QR code * @ Param name: name of the QR code file (without a suffix) * @ Param content QR code content * @ return QR code image path */public static string makeqrcode (string filepath, stri Ng name, string content) {string retpath = ""; try {// string content = "120605181003; http://www.cnblogs.com/jtmjx"; // string Path = fileoperator. getrootpath (); string Path = filepath; // httprequest. getsession (). getservletcontext (). getrealpath ("/sealandsignimages"); multiformatwriter = new multiformatwriter (); map hints = new hashmap (); hints. put (encodehinttype. character_set, "UTF-8" ); Bitmatrix = multiformatwriter. encode (content, barcodeformat. qr_code, 200,200, hints); file file1 = new file (path, name + ". jpg "); matrixtoimagewriter. writetofile (bitmatrix, "jpg", file1); retpath = file1.getabsolutepath ();} catch (exception e) {e. printstacktrace ();} return retpath;} public static void analysisqrcode () {try {multiformatreader formatreader = new multiformatreader (); strin G filepath = "F:/users/Administrator/desktop/testimage/test.jpg"; file = new file (filepath); bufferedimage image = ImageIO. read (File); luminancesource source = new bufferedimageluminancesource (image); binarizer = new hybridbinarizer (source); binarybitmap = new binarybitmap (binarizer ); map hints = new hashmap (); hints. put (encodehinttype. character_set, "UTF-8"); Result = Formatreader. decode (binarybitmap, hints); system. out. println ("result =" + result. tostring (); system. out. println ("resultformat =" + result. getbarcodeformat (); system. out. println ("resulttext =" + result. gettext ();} catch (exception e) {e. printstacktrace () ;}} package liupeng; import COM. google. zxing. common. bitmatrix; import javax. imageIO. imageIO; import Java. io. file; import Java. io. outputstream; import ja Va. io. ioexception; import Java. AWT. image. bufferedimage; public final class matrixtoimagewriter {Private Static final int black = 0xff000000; Private Static final int white = 0 xffffffff; private matrixtoimagewriter () {} public static bufferedimage partition (bitmatrix matrix) {int width = matrix. getwidth (); int Height = matrix. getheight (); bufferedimage image = new bufferedimage (width, height, Bufferedimage. type_int_rgb); For (INT x = 0; x <width; X ++) {for (INT y = 0; y
Note: You need to import org. JSON. jar and zxing-core-2.0.jar