String To Bitmap BufferedImage - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage

Description

String To Bitmap BufferedImage

Demo Code


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

import java.io.InputStream;
import javax.imageio.ImageIO;

public class Main {
    public static void main(String[] argv) throws Exception {
        String img = "java2s.com";
        System.out.println(StringToBitmap(img));
    }//  ww w.  j a v  a  2 s .  co  m

    public static BufferedImage StringToBitmap(String img) {
        try {
            sun.misc.BASE64Decoder b = new sun.misc.BASE64Decoder();
            byte[] b1 = b.decodeBuffer(img);
            InputStream in = new ByteArrayInputStream(b1);
            return ImageIO.read(in);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related Tutorials