java指定由若干url生成二维码png,然后打包为zip下载
来源:互联网 发布:大伟吉他淘宝店 编辑:程序博客网 时间:2024/06/07 06:41
额,又应项目要求,需要将客户配置的url生成二维码,然后打包为zip下载
上一篇是根据url生成图片打包下载,此篇仅仅多个根据url生成二维码
我沉默,话不多,赢的时候才开口.上代码
//公共方法根据url生成二维码图片后写入输出流里 public static void getBarCodeImgByUrl(String url,OutputStream os) throws WriterException,IOException{ //二维码参数 int width = 200; // 图像宽度 int height = 200; // 图像高度 String format = "png";// 图像类型 Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>(); hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); BitMatrix bitMatrix; bitMatrix = new MultiFormatWriter().encode(url,BarcodeFormat.QR_CODE, width, height, hints); MatrixToImageWriter.writeToStream(bitMatrix, format, os); }//入口@RequestMapping("download") public void download(HttpServletRequest request, HttpServletResponse response,BcMerchantAccount userInfo,String identy){ //通过活动标识和商户id查询活动 List<info> infoList = xxService.getInfoList(XX,XX); if(infoList != null && infoList.size()>0){ ZipOutputStream zos = null; try { String downloadFilename = infoList.get(0).getfileName();//文件的名称 downloadFilename = URLEncoder.encode(downloadFilename, "UTF-8");//转换中文否则可能会产生乱码 response.setContentType("application/octet-stream");// 指明response的返回对象是文件流 response.setHeader("Content-Disposition", "attachment;filename=" + downloadFilename+".zip");// 设置在下载框默认显示的文件名 zos = new ZipOutputStream(response.getOutputStream()); for(info info:infoList ){ zos.putNextEntry(new ZipEntry(info.getBarCode_name()+".png"));//命名 getBarCodeImgByUrl(info.getUrl, zos);//拼接了url } zos.flush(); zos.close(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (WriterException e) { e.printStackTrace(); } finally{ if(zos != null){ try { zos.flush(); zos.close(); } catch (IOException e) { e.printStackTrace(); } } } } }
2 0
- java指定由若干url生成二维码png,然后打包为zip下载
- java指定若干个网络图片,打包为zip下载
- Java 批量生成二维码图片,并打包成可直接下载的zip包(spring boot)
- JAVA 根据Url把多文件打包成ZIP下载
- 数据库读取文件,并打包为zip包,然后下载(含另存为)
- WEB端 生成多张二维码图片并打包成ZIP包供下载
- JAVA ZIP压缩打包下载
- 下载文件打包 zip java
- ios打包 蒲公英生成二维码扫描下载
- 不保存批量生成二维码并压缩zip下载
- java打包文件生成zip压缩包
- 将指定文件夹里的文件打包为zip
- java将文件打包为zip
- URL生成png图
- zip格式文件打包下载
- ant 为项目生成doc文档 并打包成zip
- Java批量下载生成zip文件
- java 生成及下载zip文件
- 判断对称矩阵
- Sping对事物的支持
- 分分钟知道tiles框架是干嘛的
- 代码注释:机器学习实战第2章 k-近邻算法
- Linux学习——文件系统管理
- java指定由若干url生成二维码png,然后打包为zip下载
- hdu 1455 sticks dfs+剪枝
- Codeforces Round #404 (Div. 2) E. Anton and Permutation(分块+二分)
- 浅谈面向对象与面向过程
- Hive使用json_tuple, posexplode 解析 json
- 【OpenCV学习笔记】十四、图像几何变换
- Ubuntu 16.04 安装 L-antern
- django中 static存放位置
- PHP解耦的三重境界(浅谈服务容器)