50,503
社区成员
发帖
与我相关
我的任务
分享
Map<EncodeHintType, Object> hints = new HashMap<>();
hints.put(EncodeHintType.CHARACTER_SET, CharacterSetECI.UTF8);// 设置编码字符集utf-8
hints.put(EncodeHintType.MARGIN, margin);
BarcodeFormat format = BarcodeFormat.PDF_417;
// 创建位矩阵对象
BitMatrix bitMatrix = null;
try {
// 生成二维码对应的位矩阵对象
bitMatrix = new MultiFormatWriter().encode(contents, format, width, height, hints);
} catch (WriterException e) {
e.printStackTrace();
}
// 设置位矩阵转图片的参数
MatrixToImageConfig config = new MatrixToImageConfig(Color.black.getRGB(), Color.white.getRGB());
// 位矩阵对象转BufferedImage对象
BufferedImage qrcode = MatrixToImageWriter.toBufferedImage(bitMatrix, config);
ImageIO.write(qrcode, "png", new File("E:/111.png"));