Java BufferedImage Encode encodeImage(BufferedImage image)

Here you can find the source of encodeImage(BufferedImage image)

Description

encode Image

License

Open Source License

Declaration

public static String encodeImage(BufferedImage image) 

Method Source Code


//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;
    }
}

Related

  1. encode(RenderedImage image, String formatName)
  2. encodeAndWriteJPEGFile(File file, BufferedImage image, float quality)
  3. encodeBufferedImageAsJPEG(BufferedImage bi)
  4. encodeImage(BufferedImage image)
  5. encodeImageToBase64(BufferedImage image)
  6. encodeImageToPNGByteArray(BufferedImage image)
  7. encodeJPEG(BufferedImage image)
  8. encodePNG(BufferedImage image, String pathAndFileName)