zxing 生成二维码 去白色补丁
2016-05-24 15:28
309 查看
`String content = "120605181003;http://www.cnblogs.com/jtmjx";
String path = "/Users/yindingyu/xxx/";
String path = "/Users/yindingyu/xxx/";
MultiFormatWriter multiFormatWriter = new MultiFormatWriter(); Map hints = Maps.newHashMap(); hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); hints.put(EncodeHintType.MARGIN, 0);//去掉白色边框 BitMatrix bitMatrix = null; try { bitMatrix = multiFormatWriter.encode(content, BarcodeFormat.QR_CODE, 246, 246,hints); } catch (WriterException e) { e.printStackTrace(); } Path file = Paths.get(path); try { MatrixToImageWriter.writeToStream(bitMatrix, qRconfig.getImageFormat(), outputStream); } catch (IOException e) { log.error("生成二维码时出现问题",e); throw ExceptionUtil.getException(ResponseCode.GEN_QR_CODE_ERROR); }`