Here you can find the source of encodeToString(BufferedImage image, String type)
Parameter | Description |
---|---|
image | the image |
type | the type |
private static String encodeToString(BufferedImage image, String type)
//package com.java2s; //License from project: Open Source License import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.IOException; import javax.imageio.ImageIO; import javax.xml.bind.DatatypeConverter; public class Main { /**/*from ww w. jav a 2 s .c om*/ * Encode to string. * * @param image the image * @param type the type * @return the string */ private static String encodeToString(BufferedImage image, String type) { String imageString = null; ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { ImageIO.write(image, type, bos); byte[] imageBytes = bos.toByteArray(); imageString = DatatypeConverter.printBase64Binary(imageBytes); bos.close(); } catch (IOException e) { e.printStackTrace(); } return imageString; } }