code: public static String imgToBase64Str(BufferedImage image, String formatName) {
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          String base64Str = null;
          try {
              ImageIO.write(image, formatName == null ? "jpeg" : formatName, baos);
              byte[] bytes = baos.toByteArray();
              base64Str = CommonUtils.bytesToBase64Str(bytes);
          } catch (IOException e) {
              throw new RuntimeException(e);
          } finally {
              CommonUtils.closeIOStream(null, baos);
          }
          return base64Str;
      }
docs: 将一张图片转换成指定格式的Base64字符串编码
  
  @param image      指定一张图片
  @param formatName 图片格式名,如gif,png,jpg,jpeg等,默认为jpeg
  @return 返回编码好的字符串, 失败返回null