标签:ref try buffer exception cep mina 下载 top iter
生成二维码
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 {
//生成二维码
public static void main(String[]
args) {
int width
= 300;
int height = 300;
String format = "png";
String content = "姓名:冯嘉伟";
//定义二维码参数
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);//生成二维码
} catch
(Exception e) {
// TODO
Auto-generated catch block
e.printStackTrace();
}
}
}
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;
//解析二维码
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("解析结果"+result.toString());
System.out.println("二维码格式类型"+result.getBarcodeFormat());
System.out.println("二维码文本内容"+result.getText());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
注意:<script type="text/javascript" src="<%request.getContextPath()%>">/js/jquery.min.js</script>
<script type="text/javascript"
src="<%request.getContextPath()%>">/js/jquery.qrcode.js</script>
这两个js包的顺序不能颠倒,否则会失败
详细的使用在一步网址中有how to use 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>
"生成的二维码如下:"<br>
<div id="qrcode">
</div>
<script type="text/javascript">
jQuery("#qrcode").qrcode("www.baidu.com");
</script>
</body>
标签:ref try buffer exception cep mina 下载 top iter
原文地址:http://www.cnblogs.com/JimCalark/p/6754670.html