二維碼生成
阿新 • • 發佈:2017-06-24
table exce tof rate javase orm pre app light
項目中用到的,以免以後會再次遇到。
一。需要兩個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; }
二維碼生成