public static String createQrcodeImg(String content,String filename,String logoPath,int imgHeight,int imgWidth){
String retstr = "";
File file = new File(filename);
MultiFormatWriter multiFormatWriter = null;
BitMatrix bm = null;
BufferedImage image = null;
try {
multiFormatWriter = new MultiFormatWriter();
Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
hints.put(EncodeHintType.MARGIN, 0);
bm = multiFormatWriter.encode(content, BarcodeFormat.QR_CODE, imgWidth, imgHeight,hints);
int w = bm.getWidth();
int h = bm.getHeight();
image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
image.setRGB(x, y, bm.get(x, y) ?Color.BLACK.getRGB() : Color.WHITE.getRGB());
}
}
BufferedImage imagelogo = image;
Graphics2D g = imagelogo.createGraphics();
File logofile = new File(logoPath);
BufferedImage logo = ImageIO.read(logofile);
int widthLogo = logo.getWidth(null) > imagelogo.getWidth() * 2 / 10 ? (imagelogo.getWidth() * 2 / 10) : logo.getWidth(null), heightLogo = logo
.getHeight(null) > imagelogo.getHeight() * 2 / 10 ?
(imagelogo.getHeight() * 2 / 10) : logo.getWidth(null);
int x = (imagelogo.getWidth() - widthLogo) / 2;
int y = (imagelogo.getHeight() - heightLogo) / 2;
g.drawImage(logo, x, y, widthLogo, heightLogo, null);
g.drawRoundRect(x, y, widthLogo, heightLogo, 15, 15);
g.drawRect(x, y, widthLogo, heightLogo);
g.dispose();
logo.flush();
imagelogo.flush();
ImageIO.write(image, "png", file);
Thread.sleep(500);
retstr = SysUtil.RET_SUCCESS;
} catch (WriterException e) {
log.error("error",e);
retstr = SysUtil.RET_FAIL;
}
return retstr;
}