code: public static String imgToBase64StrWithPrefix(BufferedImage image, String formatName) {
          formatName = formatName != null ? formatName : "jpeg";
          return String.format("data:image/%s;base64,%s", formatName, imgToBase64Str(image, formatName));
      }
docs: 将一张图片转换成指定格式的Base64字符串编码,带类似于"data:image/png;base64,"前缀,
  返回的字符串可直接放入HTML img标签src属性中显示图片
  
  @param image      指定一张图片
  @param formatName 图片格式名,如gif,png,jpg,jpeg等,默认为jpeg
  @return 返回编码好的字符串, 失败返回null