首页 > 代码库 > 二维码生成
二维码生成
项目中用到的,以免以后会再次遇到。
一。需要两个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; }
二维码生成
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。