程序运行正常 但是就是不能生成二维码
package com.zxing;
import java.io.File;
import java.nio.file.Path;
import java.util.HashMap;
import com.google.zxing.*;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
public class CreatQRcode {
public static void main(String[] args) {
// TODO 自动生成的方法存根
int width=300;
int height=300;
String format = "png";
String contents = "www.immoc.com";
//定义二维码的参数
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(contents, BarcodeFormat.QR_CODE, width, height,hints);
Path file = new File("D:/eclipse/immoc.png").toPath();
MatrixToImageWriter.writeToPath(bitMatrix, format, file);
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
}