| | |
| | | static BASE64Encoder encoder = new sun.misc.BASE64Encoder(); |
| | | static BASE64Decoder decoder = new sun.misc.BASE64Decoder(); |
| | | |
| | | @Value("${picture.addUrl}") |
| | | private String picAddUrl; |
| | | |
| | | @Value("${picture.pre}") |
| | | private static String picPre; |
| | | private static String PRE_URL = "software/minio/data/jfpt/animalHeat/"; |
| | | |
| | | /** |
| | | * 二进制原始数据转换为图片 |
| | |
| | | public static String base64StringToImage(String base64String){ |
| | | try { |
| | | byte[] bytes1 = decoder.decodeBuffer(base64String); |
| | | |
| | | ByteArrayInputStream bais = new ByteArrayInputStream(bytes1); |
| | | BufferedImage bi1 = ImageIO.read(bais); |
| | | String yyyyMMddHHmmss = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); |
| | | File w2 = new File("D://"+picPre+StringPool.SLASH+ DateUtil.today()+StringPool.SLASH+ StringUtil.randomUUID() |
| | | File w2 = new File("D://"+PRE_URL+StringPool.SLASH+ DateUtil.today()+StringPool.SLASH+ StringUtil.randomUUID() |
| | | +".jpg");//可以是jpg,png,gif格式 |
| | | |
| | | //判断父文件夹存在与否 |
| | | File parentFile = w2.getParentFile(); |
| | | System.out.println("parentFile = " + parentFile); |
| | | if (!parentFile.exists()){ |
| | | //如果不存在,则创建 |
| | | parentFile.mkdirs(); |
| | | } |
| | | ImageIO.write(bi1, "jpg", w2);//不管输出什么格式图片,此处不需改动 |
| | | //返回图片路径 |
| | | return picPre+ StringPool.SLASH+ DateUtil.today()+StringPool.SLASH+ StringUtil.randomUUID() |
| | | return PRE_URL+ StringPool.SLASH+ DateUtil.today()+StringPool.SLASH+ StringUtil.randomUUID() |
| | | +StringPool.DOT+ "jpg"; |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |