Generate two-dimensional code
Java generates two-dimensional code: The idea is to get the jar bag know the method used in step one, download in https://github.com/zxing (click on the page named zxing a tag, jump to the source page, click Release to see all the published source code, Download zip archive Step One: After extracting the file, open the folder and copy the COM package from the core package and Javase package to a Java Project src directory. Right-click Export Jar file to get a two-dimensional code to develop the jar package step three: making two-dimensional code
Import Java.io.File;
Import java.io.IOException;
Import Java.nio.file.Path;
Import Java.util.HashMap;
Import Com.google.zxing.BarcodeFormat;
Import Com.google.zxing.EncodeHintType;
Import Com.google.zxing.MultiFormatWriter;
Import com.google.zxing.WriterException;
Import Com.google.zxing.client.j2se.MatrixToImageWriter;
Import Com.google.zxing.common.BitMatrix;
Import Com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
public class Createqrcode {
Generate two-dimensional code
public static void Main (String[]args) {
int width= 300;
int height = 300;
String format = "png";
String content = "Name: Feng Jiawei";
Define two-dimensional code parameters
HashMap hints = new HashMap ();
Hints.put (Encodehinttype.character_set, "utf-8");
Hints.put (Encodehinttype.error_correction, ERRORCORRECTIONLEVEL.M);
Hints.put (Encodehinttype.margin, 2);
try {
Bitmatrix Bitmatrix = new Multiformatwriter (). Encode (content, Barcodeformat.qr_code, width, height,hints);
Path file = new file ("D:/code/img.png"). Topath ();
Matrixtoimagewriter.writetopath (Bitmatrix, format, file);//Generate two-dimensional code
} catch (Exception e) {
//todoauto-generated Catch block
E.printstacktrace ();
}
}
}
Two-dimensional Code parser
Import Java.awt.image.BufferedImage;
Import Java.io.File;
Import java.io.IOException;
Import Java.util.HashMap;
Import Javax.imageio.ImageIO;
Import Com.google.zxing.BinaryBitmap;
Import Com.google.zxing.EncodeHintType;
Import Com.google.zxing.MultiFormatReader;
Import Com.google.zxing.Result;
Import Com.google.zxing.client.j2se.BufferedImageLuminanceSource;
Import Com.google.zxing.common.HybridBinarizer;
Parsing two-dimensional code
public class Readqrcode {
public static void Main (string[] args) {
try {
Multiformatreader Formatreader = new Multiformatreader ();
File File = new file ("D:/code/img.png");
BufferedImage image = ImageIO.Read(file);
Binarybitmap Binarybitmap = new Binarybitmap (new Hybridbinarizer (new Bufferedimageluminancesource (image));
HashMap hints = new HashMap ();
Hints.put (Encodehinttype.character_set, "utf-8");
Result result = Formatreader.decode (binarybitmap,hints);
System. out. println ("Analytic results" +result.tostring ());
System. out. println ("Two-dimensional code format type" +result.getbarcodeformat ());
System. out. println ("QR Code text content" +result.gettext ());
} catch (Exception e) {
//TODO auto-generated Catch block
E.printstacktrace ();
}
}
}
Generate QR code with jquery Step one: Https://github.com/jeromeetienne/jquery-qrcode Step two: Release download jquery package step three: Import JS package in front
Note: <script type= "Text/javascript" src= "<%request.getcontextpath ()%>" >/js/jquery.min.js</script >
<script type= "Text/javascript" src= "<%request.getcontextpath ()%>" >/js/jquery.qrcode.js</script >
The order of the two JS packets cannot be reversed, otherwise it will fail
Detailed use in the one-step URL has how-to uses it
<script type= "Text/javascript" src= "<%request.getcontextpath ()%>" >/js/jquery.min.js</script>
<script type= "Text/javascript" src= "<%request.getcontextpath ()%>" >/js/jquery.qrcode.js</script >
<body>
"The generated QR code is as follows:" <br>
<div id= "QRCode" >
</div>
<script type= "Text/javascript" >
JQuery ("#qrcode"). QRCode ("www.baidu.com");
</script>
</body>
Java generates two-dimensional code and jquery generates QR code