我是靠谱客的博主 发嗲香菇,这篇文章主要介绍zxing生成二维码以流式传到页面,现在分享给大家,希望可以做个参考。

@RequestMapping(“/makeQrCode”)
public void madeQrCode(HttpServletResponse res,String content,Integer width,Integer height) throws IOException{


String format = "png";
content = (content == null || "".equals(content) ? "http://www.manjiwang.com" : content);
width = (width == null ? 300 : width);
height = (height == null ? 300 : height);
System.out.println(content);
System.out.println(width);
System.out.println(height);
if(content != null && !"".equals(content)){
ServletOutputStream stream = null;
try {
//定义二维码的参数
HashMap hints = new HashMap();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
hints.put(EncodeHintType.MARGIN, 2);
//生成二维码
stream = res.getOutputStream();
BitMatrix bitMatrix = new QRCodeWriter().encode(content, BarcodeFormat.QR_CODE, width, height , hints);
MatrixToImageWriter.writeToStream(bitMatrix, format, stream);
} catch (WriterException e) {
e.printStackTrace();
}finally{
if(stream != null){
stream.flush();
stream.close();
}
}
}
}

前端页面接收

$(“#image”).attr(“src”,”/backstage/makeQrCode?content=”+content+”&width=”+width+”&height=”+height);

最后

以上就是发嗲香菇最近收集整理的关于zxing生成二维码以流式传到页面的全部内容,更多相关zxing生成二维码以流式传到页面内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(111)

评论列表共有 0 条评论

立即
投稿
返回
顶部