Here you can find the source of encodeToString(BufferedImage image, String type)
public static String encodeToString(BufferedImage image, String type) throws Exception
//package com.java2s; //License from project: Open Source License import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import sun.misc.BASE64Encoder; import javax.imageio.ImageIO; public class Main { /**//from w ww .j a v a2 s .c o m * Encode image to string */ public static String encodeToString(BufferedImage image, String type) throws Exception { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ImageIO.write(image, type, bos); byte[] imageBytes = bos.toByteArray(); BASE64Encoder encoder = new BASE64Encoder(); String imageString = encoder.encode(imageBytes); bos.close(); return imageString; } }