使用zxing core javase 3.3.0版本的jar包生成二维码,单独在一个类中可以生成出二维码,但是把该代码封装到类中,在servlet中调我封装的类就会报classnotfoundexception,有知道是为什么的吗?
int width=300;
int height=300;
String format="png";
//生成的二维码存在的位置及二维码名字
String path="F:\\two.png";
String content="生成一个二维码";
HashMap hash=new HashMap();
hash.put(EncodeHintType.CHARACTER_SET,"utf-8");
hash.put(EncodeHintType.ERROR_CORRECTION,ErrorCorrectionLevel.M);
hash.put(EncodeHintType.MARGIN, 2);
try {
BitMatrix bitMatrix=new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height,hash);
Path file=new File(path).toPath();
MatrixToImageWriter.writeToPath(bitMatrix, format, file);
System.out.println("ok");
}catch(Exception e) {
e.printStackTrace();
}
作者:方叶
来源:CSDN
原文:https://blog.csdn.net/weixin_44563697/article/details/88577455
版权声明:本文为博主原创文章,转载请附上博文链接!