图片输出浏览器

2019-02-19  本文已影响0人  尼古拉斯_谭
/**
     * 算法结果下载
     * @return
     */
    @RequestMapping("/billingDownloadOutWrite")
    public  void   billingDownloadOutWrite(@NotNull(message = "key不能为空") String ossKey,HttpServletRequest request,
                                    HttpServletResponse response){
        try{
                LOG.info("开始获取key:{}",MessageConstant.Default.BASIC_DIRECTORY+ossKey);
                InputStream inputStream = AliOSSUtils.getObject(MessageConstant.Default.BASIC_DIRECTORY+ossKey);
                BufferedImage bi = ImageIO.read(inputStream);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            String[] urlSplit = ossKey.split("[.]");
            ImageIO.write(bi, urlSplit[1], baos);  //经测试转换的图片是格式这里就什么格式,否则会失真
            response.setHeader("Content-Type", "image/jpeg");
            ImageIO.write(bi, urlSplit[1], response.getOutputStream());
        }catch (Exception e){
            e.printStackTrace();
        }
    }

上一篇下一篇

猜你喜欢

热点阅读