Here you can find the source of encodeImage(BufferedImage image)
public static String encodeImage(BufferedImage image)
//package com.java2s; //License from project: Open Source License import java.io.*; import java.awt.image.*; import javax.imageio.*; import javax.xml.bind.*; public class Main { public static String encodeImage(BufferedImage image) { String imageString = null; ByteArrayOutputStream bos = new ByteArrayOutputStream(); try {//w ww . j ava2 s.c om ImageIO.write(image, "png", bos); byte[] imageBytes = bos.toByteArray(); imageString = DatatypeConverter.printBase64Binary(imageBytes); bos.close(); } catch (IOException e) { e.printStackTrace(); } return imageString; } }