/**
* 获取二维码
*
* @throws IOException
*/
public static void createqrImg(String path,String codetype, String telephone, String mecode, String meetname, HttpServletRequest request) throws IOException {
//String targetFile = request.getSession().getServletContext().getRealPath("/");
//String path = targetFile + "print/" + meetname + ".png";
//String path = targetFile +pathname;
if (!"".equals(telephone) && telephone != null) {
mecode = telephone;
}
if ("1".equals(codetype)) {
// LMH 2015.3.27 生成二维码
BitMatrix byteMatrix = null;
try {
byteMatrix = new MultiFormatWriter().encode(new String(mecode.getBytes("UTF-8"), "iso-8859-1"), BarcodeFormat.QR_CODE, 650, 650);
} catch (WriterException e) {
e.printStackTrace();
}
File file = new File(path);
if (!file.exists())
file.mkdirs();
MatrixToImageWriter.writeToFile(byteMatrix, "png", file);
} else {
File outputFile = new File(path);
OutputStream out = new FileOutputStream(outputFile);
Code128Bean bean = new Code128Bean();
final int dpi = 2000;
bean.setModuleWidth(0.55);
bean.setMsgPosition(HumanReadablePlacement.HRP_NONE);// 数字位置
BitmapCanvasProvider canvas = new BitmapCanvasProvider(out, "image/jpeg", dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0);
if (mecode == null) {
bean.generateBarcode(canvas, "error code");
} else {
bean.generateBarcode(canvas, mecode);
}
canvas.finish();
out.close();
}
}