为什么要用到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();
}
}
} |