文奇0
2017-01-06 21:49
Path file=new File("D:/迅雷下载/img.png")
.toPath();一直出错是怎么回事
你知道那个包怎么引入呢?
//你的问题可能是引入的包不对
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;
/**
* @descrption:生成二维码
* @author pwu
*
*/
public class CreateQRcode {
public static void main(String[] args) {
int width=300;
int height=300;
String format="png";
String contents="http://www.imooc.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:/Qrcode-zxing.png").toPath();
MatrixToImageWriter.writeToPath(bitMatrix, format, file);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Java生成二维码
84502 学习 · 204 问题
相似问题