code: private static String getBase64Data(BufferedImage buffImage,
              String formatName, Node node) throws Exception {
          int numBytes = buffImage.getWidth() * buffImage.getHeight() * 4;
          ByteArrayOutputStream baos = new ByteArrayOutputStream(numBytes);
          ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
          boolean status = ImageIO.write(buffImage, formatName, ios);
          if (!status) {
              throw new Exception(
                      "No suitable ImageIO writer found by ImageParser.getBase64Data() for image format "
                              + formatName);
          }
          byte[] imageData = baos.toByteArray();
          // String base64String = Base64.encodeBase64String(imageData); this is
          // unchunked (no line breaks) which is unwieldy
          byte[] base64Data = Base64.encodeBase64Chunked(imageData);
          // 2011-11-15 PwD uncomment for Java 1.7 String base64String = new
          // String(base64Data, StandardCharsets.UTF_8);
          String base64String = new String(base64Data, "UTF-8"); // 2011-11-15 PwD
                                                                 // for Java 1.6;
                                                                 // remove for
                                                                 // Java 1.7
          return base64String;
      }
docs: /*
  2011-09-08 PwD
  
  @return image data as a base64 encoded string