/**
* 生成二维码
*
* @param contents
* @param width
* @param height
* @param imgPath
* @return
*/
public static InputStream qrCodeEncode(String contents, int width,
int height, String imgPath) {
Map<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
// 指定纠错等级
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
// 指定编码格式
hints.put(EncodeHintType.CHARACTER_SET, "UTF8");
hints.put(EncodeHintType.MARGIN, 0);
try {
BitMatrix bitMatrix = new MultiFormatWriter().encode(contents,
BarcodeFormat.QR_CODE, width, height, hints);
OutputStream os = new FileOutputStream(imgPath);
MatrixToImageWriter.writeToStream(bitMatrix, "png", os);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
补充:二维码生成
最新推荐文章于 2024-02-26 16:11:58 发布