标签:物理 app str write 生成二维码 class idt getname null
项目中用到的,以免以后会再次遇到。
一。需要两个jar包
zxing-javase.jar
zxing.jar
二。配置需要生成二维码的参数
三。生成二维码方法,方法返回值可改变
//生成二维码
public String generateQRCode(String orderId,String qrCode){
try {
//物理路径
String path = ApplicationContext.getProperty("RechargeCode");
File file = new File(path);
String filePath = file.getName() + File.separator + orderId + ".png";
path += orderId + ".png";
int width = 900;
int height = 900;
String format = "png";
Hashtable hints= new Hashtable();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
BitMatrix bitMatrix = new MultiFormatWriter().encode(qrCode, BarcodeFormat.QR_CODE, width, height,hints);
File outputFile = new File(path);
MatrixToImageWriter.writeToFile(bitMatrix, format, outputFile);
return filePath;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
标签:物理 app str write 生成二维码 class idt getname null
原文地址:http://www.cnblogs.com/wuao/p/7073924.html