QR codes are very popular now.
The front end also has two-dimensional code generation way: Jquery.qrcode
QRCode is actually achieved by using jquery to achieve graphical rendering, supporting HTML5 technology, as long as it is implemented by canvas. Transmission Door
Java generated two-dimensional code is very mature, and compatibility is very good.
Directly download the jar package transmission door
There are Core-3.0.0.jar and Base64encoder.jar two jar packages in the download file.
The first one is the QR code, the second one is used by Base64.
Do not convert base64 can not use a second
Import into the project to use it.
Basic Use Method:
Publicstring generalqrcode (string url) {Hashtable hints=NewHashtable (); Hints.put (Encodehinttype.character_set,"Utf-8"); String binary=NULL; Try {
400,400 is a two-dimensional code picture width high Bitmatrix bitmatrix=NewMultiformatwriter (). Encode (URL, Barcodeformat.qr_code,400, 400, hints); //implementation of a: output image to the specified directory//file OutputFile = new file ("D://1.jpg ");//Matrixtoimagewriter.writetofile (Bitmatrix, "PNG", outputFile); //implementation of two: Generate two-dimensional code image and convert the picture to a binary system to pass to the foreground//1. read file conversion to byte arrayBytearrayoutputstream out =NewBytearrayoutputstream (); BufferedImage Image=tobufferedimage (Bitmatrix); ////Imageio.write (Image, "PNG", out); byte[] bytes =Out.tobytearray (); //2. Convert byte array to binaryBase64encoder encoder =NewBase64encoder (); Binary=encoder.encodebuffer (bytes). Trim (); } Catch(Exception e) {e.printstacktrace (); } return"Data:image/png;base64," +binary; } Public Staticbufferedimage tobufferedimage (Bitmatrix matrix) {intwidth =matrix.getwidth (); intHeight =matrix.getheight (); BufferedImage Image=Newbufferedimage (width, height, bufferedimage.type_int_rgb); for(intx = 0; x < width; X + +) { for(inty = 0; Y < height; y++) {Image.setrgb (x, Y, Matrix.get (x, y)? 0xff000000:0xffffffff); } } returnimage; }
After the guide package is copied directly into the project can be used.
If it is the SPRINGMVC framework, the Generalqrcode method can be directly released to the controller to be called at the front end.
As an example of annotations:
@RequestMapping ("/generalqrcode.do")
@ResponseBody
java-QR code generation page Output