Here you can find the source of imageAsBase64Png(Component c)
static String imageAsBase64Png(Component c)
//package com.java2s; //License from project: Open Source License import java.awt.*; import java.awt.image.*; import javax.imageio.ImageIO; import java.io.ByteArrayOutputStream; public class Main { static String imageAsBase64Png(Component c) { if (c.getWidth() <= 0 || c.getHeight() <= 0) { return ""; }//from w ww . jav a 2 s .c o m BufferedImage img = new BufferedImage(c.getWidth(), c.getHeight(), BufferedImage.TYPE_INT_RGB); c.paint(img.getGraphics()); ByteArrayOutputStream buf = new ByteArrayOutputStream(); try { ImageIO.write(img, "png", buf); } catch (java.io.IOException ex) { return ex.toString(); } return javax.xml.bind.DatatypeConverter.printBase64Binary(buf.toByteArray()); } }