• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

跟不上老师的步调 不太懂这节代码的意思

为什么要用到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 hints = new HashMap();
                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

用HashMap是因为MultiFormatWriter().encode()方法需要一个HashMap作为参数,而map中的内容是zxing开源项目所规定的一些配置项,以下代码可以体现出来:
//encode()方法最后一个参数hints就是那个HashMap。HashMaphints=newHashMap();BitMatrixbitmatrix=newMultiFormatWriter().encode(content,BarcodeFormat.QR_CODE,width,height,hints);望采纳。

使用道具 举报

发新帖

发布任务需求已有1031167位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!