使用zing庫,輸入中文內容,生成條形碼,用軟體掃這個條形碼,出來的是亂碼,英文和數字是正常的,請問有人知道怎么解決嗎
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"));
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/249227.html
標籤:Java相關
下一篇:springboot啟動專案時配置連接服務器端zookeeper的(服務端地址:2181),但是日志顯示連接本機的(127.0.0.1:2181),導致啟動報錯
