Java Utililty Methods BufferedImage to Base64 String

List of utility methods to do BufferedImage to Base64 String

Description

The list of methods to do BufferedImage to Base64 String are organized into topic(s).

Method

StringimageToBase64(BufferedImage image)
image To Base
ByteArrayOutputStream out = new ByteArrayOutputStream(BUFFER_SIZE);
ImageIO.write(image, "png", out);
return Base64.getEncoder().encodeToString(out.toByteArray());
StringimageToBase64String(BufferedImage image, String type)
image To Base String
String imageString = null;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
    ImageIO.write(image, type, bos);
    byte[] imageBytes = bos.toByteArray();
    imageString = Base64.getEncoder().encodeToString(imageBytes);
    bos.close();
} catch (IOException e) {
...
StringimageToBase64String(RenderedImage image, String type)
Encode image to string
String ret = null;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
    ImageIO.write(image, type, bos);
    byte[] bytes = bos.toByteArray();
    BASE64Encoder encoder = new BASE64Encoder();
    ret = encoder.encode(bytes);
    ret = ret.replace(System.lineSeparator(), "");
...