提问人:SOJSON用户
提问日期:2017-02-22 23:04
热度:139
/**
* 输出二维码
* @param response
* @param id
*/
@RequestMapping(value="swf/{id}",method=RequestMethod.GET)
public void swf(HttpServletResponse response,HttpServletRequest request,@PathVariable("id")String id){
response.setContentType("image/png");
try {
String text = id; //二维码内容
int width = 150; //宽
int height = 150; //高
Hashtable<EncodeHintType,Object> hints= new Hashtable<EncodeHintType,Object>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
BitMatrix bitMatrix = new MultiFormatWriter().encode(text, BarcodeFormat.QR_CODE, width, height,hints);
//输出二维码
MatrixToImageWriter.writeToStream(bitMatrix, "PNG", response.getOutputStream());
} catch (Exception e) {
LoggerUtils.fmtError(getClass(), e, "文件输出错误:[%s]", id);
}
}
0条回答
我来回答