亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

沒有報紅,運行時出錯

? int w = 300;
? ? ? ?int h = 300;
? ? ? ?String formt = ".png";
? ? ? ?String content = "www.baidu.com";
// ? ? ? ?定義二維碼參數
? ? ? ?HashMap hints = new HashMap();
? ? ? ?hints.put(EncodeHintType.CHARACTER_SET, "utf-8");//字符集
? ? ? ?hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);//出錯等級
? ? ? ?hints.put(EncodeHintType.MARGIN, 2);//邊距,生成的二維碼的空白部分,默認是5
// ? ? ? ?生成
? ? ? ?try {
? ? ? ? ? ?BitMatrix encode = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, w, h, hints);
// ? ? ? ? ? ?生成二維碼
? ? ? ? ? ?Path file = new File("G:/img.png").toPath();
? ? ? ? ? ?MatrixToImageWriter.writeToPath(encode,formt,file);

? ? ? ?} catch (Exception e) {
? ? ? ? ? ?e.printStackTrace();
? ? ? ?}

運行后:

java.io.IOException: Could not write an image of format .png to G:\img.png

正在回答

1 回答

已經解決了,定義類型的時候多寫了個.

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

沒有報紅,運行時出錯

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號