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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

跟不上老師的步調 不太懂這節代碼的意思

跟不上老師的步調 不太懂這節代碼的意思

栗喵 2016-09-19 20:20:08
為什么要用到HashMap呢?作用是什么?按照老師的思路用myeclipse寫了之后好多警號 又根據提示改了下 但感覺思路還是不清晰 ?哪位大神能幫我加個注釋么?package com.sun;import java.io.File;import java.nio.file.Path;import java.util.HashMap;import com.google.zxing.BarcodeFormat;import com.google.zxing.EncodeHintType;import com.google.zxing.MultiFormatWriter;import com.google.zxing.WriterException;import com.google.zxing.client.j2se.MatrixToImageWriter;import com.google.zxing.common.BitMatrix;import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;//生成二維碼public class CreateQRTest { public static void main(String[] args){ //定義二維碼的長度 寬度 以及格式 int width = 300; int height = 300; String format = "png"; //二維碼內容 String content = "http://l-hs.cn/"; //定義二維碼的參數 @SuppressWarnings("rawtypes") HashMap<EncodeHintType, Comparable> hints = new HashMap<EncodeHintType, Comparable>(); hints.put(EncodeHintType.CHARACTER_SET, "utf-8");//編碼格式 hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);//糾錯 hints.put(EncodeHintType.MARGIN,2);//邊距 try { BitMatrix bitmatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height,hints); Path file = new File("C:/Users/ZILI/Desktop/love.png").toPath(); MatrixToImageWriter.writeToPath(bitmatrix, format, file); } catch (Exception e) { e.printStackTrace(); } } }
查看完整描述

1 回答

已采納
?
四無小青年

TA貢獻88條經驗 獲得超43個贊

用HashMap是因為MultiFormatWriter().encode()方法需要一個HashMap作為參數,而map中的內容是zxing開源項目所規定的一些配置項,以下代碼可以體現出來:

//encode()方法最后一個參數hints就是那個HashMap。
HashMap<EncodeHintType,?Comparable>?hints?=?new?HashMap<EncodeHintType,?Comparable>();
BitMatrix?bitmatrix?=?new?MultiFormatWriter().encode(content,?BarcodeFormat.QR_CODE,?width,?height,hints);

望采納。

查看完整回答
反對 回復 2016-09-19
  • 1 回答
  • 0 關注
  • 3621 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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