BufferedImage Bitmap To String - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Convert

Description

BufferedImage Bitmap To String

Demo Code


//package com.java2s;
import java.awt.image.BufferedImage;

import java.io.ByteArrayOutputStream;

import javax.imageio.ImageIO;

public class Main {
    public static String BitmapToString(BufferedImage dwBit) {
        try {/* w  w w . jav  a2  s .c o  m*/
            ByteArrayOutputStream a2 = new ByteArrayOutputStream();
            ImageIO.write(dwBit, "jpg", a2);
            a2.flush();
            byte[] a3 = a2.toByteArray();
            a2.close();
            String a1 = null;
            a1 = new sun.misc.BASE64Encoder().encode(a3);
            return a1;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related Tutorials