Java BufferedImage Encode encode(RenderedImage image, String formatName)

Here you can find the source of encode(RenderedImage image, String formatName)

Description

encode

License

Open Source License

Declaration

public static String encode(RenderedImage image, String formatName) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.image.RenderedImage;
import java.io.BufferedOutputStream;

import java.io.ByteArrayOutputStream;

import java.io.IOException;
import java.util.Base64;
import javax.imageio.ImageIO;

public class Main {
    public static String encode(RenderedImage image, String formatName) {
        try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
                BufferedOutputStream bos = new BufferedOutputStream(baos);) {
            ImageIO.write(image, formatName, bos);
            bos.flush();//w w w . j ava 2  s .  c  o m
            return Base64.getEncoder().encodeToString(baos.toByteArray());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. encodeAndWriteJPEGFile(File file, BufferedImage image, float quality)
  2. encodeBufferedImageAsJPEG(BufferedImage bi)
  3. encodeImage(BufferedImage image)
  4. encodeImage(BufferedImage image)