图片下载

/***  图片类型* @param path    图片地址* @param id      uuid* @param isAspose* @return* @throws IOException*/private String setSignImage(String path, String id, boolean isAspose) throws IOException {String result = "";try {// 图片路径不为空if (StringUtils.isNotEmpty(path) && !path.equals("null")) {BufferedInputStream bin = null;FileOutputStream out = null;String imagepath = null;try {//图片完整地址String urlPath = fastdfs_server + "/" +path;// 统一资源URL url = new URL(urlPath);logger.info("file path is : " + urlPath);// 连接类的父类,抽象类URLConnection urlConnection = url.openConnection();// http的连接类HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;// 设置字符编码httpURLConnection.setRequestProperty("Charset", "UTF-8");// 打开到此 URL 引用的资源的通信链接(如果尚未建立这样的连接)。httpURLConnection.connect();bin = new BufferedInputStream(httpURLConnection.getInputStream());String fileType = HttpURLConnection.guessContentTypeFromStream(bin);fileType = fileType.split("/")[1];//生成本地图片路径String binPath = System.getProperty("user.dir");logger.info("binPath=" + binPath);if (binPath.endsWith(File.separator)) {binPath = binPath.substring(0, binPath.length() - 1);}SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHH");//设置日期格式String appPath = binPath.substring(0, binPath.lastIndexOf(File.separator));String wordImagePath = appPath + File.separator + "webapps" + File.separator + "wordImage" + File.separator + df.format(new Date());logger.info("wordImagePath=" + wordImagePath);File toDir = new File(wordImagePath);if (!toDir.exists()) {toDir.mkdirs();}imagepath = wordImagePath + File.separator + id + "." + fileType;logger.info("图片路径{}", imagepath);out = new FileOutputStream(new File(imagepath));int size = 0;byte[] buf = new byte[1024];while ((size = bin.read(buf)) != -1) {out.write(buf, 0, size);}bin.close();out.close();} catch (Exception e) {e.printStackTrace();logger.error(e.getMessage());} finally {if (bin != null) {bin.close();}if (out != null) {out.close();}}File file = new File(imagepath);//linux 下需要加  file://imagepath = "file://" + imagepath;if (!file.exists()) {//文件下载失败logger.info("文件下载失败,或图片不存在={}", imagepath);result = "";} else {if (isAspose) {result = imagepath;} else {result = "[image]" + imagepath + "[/image]";}}} else {//查询姓名logger.info("图片不存在", "");result = "";}logger.info("图片返回值={}", result);} catch (Exception e) {logger.error("get the image is error", e);}return result;}

二维码生成

依赖

 <!-- https://mvnrepository.com/artifact/com.google.zxing/core --><dependency><groupId>com.google.zxing</groupId><artifactId>core</artifactId><version>3.3.0</version></dependency><!-- https://mvnrepository.com/artifact/com.google.zxing/javase --><dependency><groupId>com.google.zxing</groupId><artifactId>javase</artifactId><version>3.3.0</version></dependency></dependencies>
/*** 获取图片 , 二维码 条形码** @param* @throws IOException e*/private String getImage(String path, String id, boolean isAspose) throws IOException {String result = "";try {// 图片路径不为空if (StringUtils.isNotEmpty(path) && !path.equals("null")) {BufferedInputStream bin = null;FileOutputStream out = null;String imagepath = null;/* try {String urlPath = fdfsDownServer + path;// 统一资源URL url = new URL(urlPath);logger.info("file path is="+urlPath);// 连接类的父类,抽象类URLConnection urlConnection = url.openConnection();// http的连接类HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;// 设置字符编码httpURLConnection.setRequestProperty("Charset", "UTF-8");// 打开到此 URL 引用的资源的通信链接(如果尚未建立这样的连接)。httpURLConnection.connect();bin = new BufferedInputStream(httpURLConnection.getInputStream());String fileType = HttpURLConnection.guessContentTypeFromStream(bin);fileType = fileType.split("/")[1];//生成本地图片路径String binPath = System.getProperty("user.dir");logger.info("binPath=" + binPath);if (binPath.endsWith(File.separator)) {binPath = binPath.substring(0, binPath.length() - 1);}SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHH");//设置日期格式String appPath = binPath.substring(0, binPath.lastIndexOf(File.separator));String wordImagePath = appPath + File.separator + "webapps"+File.separator+"wordImage"+File.separator+df.format(new Date());logger.info("wordImagePath=" + wordImagePath);File toDir = new File(wordImagePath);if (!toDir.exists()) {toDir.mkdirs();}imagepath = wordImagePath + File.separator + id + "." + fileType;logger.info("图片路径{}", imagepath);out = new FileOutputStream(new File(imagepath));int size = 0;byte[] buf = new byte[1024];while ((size = bin.read(buf)) != -1) {out.write(buf, 0, size);}bin.close();out.close();} catch (Exception e) {e.printStackTrace();logger.error(e.getMessage());} finally {if (bin != null) {bin.close();}if (out != null) {out.close();}}*///生成本地图片路径String binPath = System.getProperty("user.dir");logger.info("binPath=" + binPath);if (binPath.endsWith(File.separator)) {binPath = binPath.substring(0, binPath.length() - 1);}SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHH");//设置日期格式String appPath = binPath.substring(0, binPath.lastIndexOf(File.separator));String wordImagePath = appPath + File.separator + "webapps" + File.separator + "wordImage" + File.separator + df.format(new Date());//路径白名单校验,路径特殊符号校验,此处不需要//wordImagePath = FileUrlWhiteListUtil.getInstance().filenameFilter(wordImagePath);logger.info("wordImagePath=" + wordImagePath);File toDir = new File(wordImagePath);if (!toDir.exists()) {toDir.mkdirs();}imagepath = wordImagePath + File.separator + id;logger.info("图片路径{}", imagepath);imagepath = HisignQRCode.createQrcode(path, 80, 80, "jpg", imagepath, 4);logger.info("图片路径{}", imagepath);File file = new File(imagepath);//linux 下需要加  file://imagepath = "file://" + imagepath;if (!file.exists()) {//文件下载失败logger.info("文件下载失败,或图片不存在={}", imagepath);result = "";} else {if (isAspose) {result = imagepath;} else {result = "[image]" + imagepath + "[/image]";}}} else {//查询姓名logger.info("图片不存在", "");result = "";}logger.info("图片返回值={}", result);} catch (Exception e) {logger.error("get the image is error", e);}return result;}

图片下载_二维码生成相关推荐

  1. js实现图片下载(二维码)

    今天遇到个二维码下载问题,下载下来的二维码扫描后失效,记录一下: 解决办法就是把src换成绝对路径 图片下载(二维码) 方法一: function getImageDataURL(downloadNa ...

  2. 【二维码】二维码生成

    一.二维码         二维码又称二维条码,常见的二维码为QR Code,QR全称Quick Response,是一个近几年来移动设备上超流行的一种编码方式,它比传统的Bar Code条形码能存更 ...

  3. java二维码生成 使用SSM框架 搭建属于自己的APP二维码合成、解析、下载

    java二维码生成 使用SSM框架 搭建属于自己的APP二维码合成.解析.下载 自己用java搭建一个属于自己APP二维码合成网站.我的思路是这样的: 1.用户在前台表单提交APP的IOS和Andro ...

  4. 二维码生成、扫描、图片识别(Zxing)

    这样的例子虽然已经很多了,不过我在网上浏览了一圈,也没找到几个图库二维码图片识别例子,好的算法识别率才高.这里有一个好点的算法,算法不是我写的,只是作为整理记录,给众多安卓开发者一个方便.demo的U ...

  5. jquery-qrcode客户端二维码生成类库扩展--融入自定义Logo图片

    淘宝就不多说了,全球最大的中文假货销售平台(尽管淘宝没有打出全球中文等字样,可是其必须当之无愧).百度,当当等厚颜无耻之徒的明智之举就在于此,老外做的再大也很少会有直接支持中文的,因此他们都会在其名称 ...

  6. react 二维码生成并下载qrcode.react

    目前几乎任何一个完整的项目都会包含二维码的生成,这时候我们就需要一个可以快速生成二维码的插件了,接下来我将介绍如何生成并下载该二维码 在react开发中如果需要二维码,本人是倾向于使用qrcode.r ...

  7. Android 实现系统打印机打印图片,文本,以及二维码生成与解析

    打码机:扫码,生成打印自定义标签   一.Android 打印机要支持,网络.WiFi :手机与打印机在同一网络下才行,本文用WiFi连接 打开系统打印服务: 设置--更多设置--打印--选择默认打印 ...

  8. jquery二维码生成插件jquery.qrcode.js,生成二维码并下载

    下载插件: 在GitHub上,下载qrcode二维码插件: https://github.com/jeromeetienne/jquery-qrcode Vue项目可直接通过node.js安装:npm ...

  9. jquery二维码生成插件_二维码生成器

    jquery二维码生成插件_二维码生成器 下载地址:jquery生成二维码.rar 转载于:https://www.cnblogs.com/wifi/articles/3176529.html

最新文章

  1. java maven项目使用sonar审核代码
  2. Java动态追踪技术探究
  3. linux solusos 软件包管理工具 eopkg 简介
  4. 网络爬虫初步:从一个入口链接开始不断抓取页面中的网址并入库
  5. 看小说有广告?不可能的,分分钟教你爬取小说
  6. Qt Qwdget 汽车仪表知识点拆解4 另类进度条实现
  7. 1. 冒泡与选择排序及其比较
  8. java基础—集合 Vcetor 基本方法演示
  9. Android通过tcpdump抓包
  10. vue地址栏输入路由跳转到首页_Vue路由跳转到新页面时 默认在页面最底部 而不是最顶部 的解决...
  11. 五笔字根表识别码图_怎么学五笔 五笔字根表键盘图 【详细介绍】
  12. 【硬石STM32f407开发板_DIY入门】模块化编程实例
  13. Java识别获取pdf中文字信息
  14. 草食と肉食作者小さな塵
  15. html网页底部代码实例,HTML网页头部代码实例详解H 这个首页的html5网站
  16. 衣橱管理APP——《衣橱管家》页面设计
  17. 征友记之---前端开发Partner
  18. 激光导引头电子舱测试系统软件的研究与开发
  19. [转贴]迅雷十年反思
  20. ReadInfo(周考1)

热门文章

  1. 华为手机安装Goole play教程及安装包
  2. 疲劳检测,基于视频的疲劳检测、脱岗、打呵欠、闭眼、点头等检测
  3. 男人心疼女人的13种方式
  4. hive实现获取当前季度第一天
  5. 连接线是计算机硬件吗,音箱线怎么连接电脑?有源音箱和无源音箱连接电脑教程...
  6. proxifier安装激活使用
  7. ggggggggggg
  8. Postman导入数据批量测试
  9. 一言 源码 android,[源码]纯净的一言API
  10. 未安装AMD图形驱动程序,或者AMD驱动程序未正常工作。请安装与AMD硬件相对应的AMD驱动程序