Base64String转为图片并保存

 /**
     *
     * @param BASE64str bas64字符串
     * @param path 存储地址
     * @return 存储地址
     */
    public static String BASE64CodeToBeImage(String BASE64str,String path){
        BufferedImage image = null;
        byte[] imageByte = null;
        try {
            imageByte = DatatypeConverter.parseBase64Binary(BASE64str);
            ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);
            image = ImageIO.read(new ByteArrayInputStream(imageByte));
            bis.close();
            File outputfile = new File(path);
            ImageIO.write(image, "jpg", outputfile);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

  

posted @ 2021-03-17 10:14  养九  阅读(530)  评论(0)    收藏  举报