Java BufferedImage from String decodeToImage(String imageString)

Here you can find the source of decodeToImage(String imageString)

Description

Decode string to image

License

Open Source License

Parameter

Parameter Description
imageString The string to decode

Return

decoded image

Declaration

public static BufferedImage decodeToImage(String imageString) 

Method Source Code


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

import sun.misc.BASE64Decoder;

import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;

import javax.imageio.ImageIO;

public class Main {
    /**//from w  w  w .  ja v a 2s  .  c  o m
     * Decode string to image
     * @param imageString The string to decode
     * @return decoded image
     */
    public static BufferedImage decodeToImage(String imageString) {

        BufferedImage image = null;
        byte[] imageByte;
        try {
            BASE64Decoder decoder = new BASE64Decoder();
            imageByte = decoder.decodeBuffer(imageString);
            ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);

            image = ImageIO.read(bis);
            bis.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return image;
    }
}

Related

  1. base64ToImage(final String data, final int width, final int height)
  2. base64ToImage(String base64)
  3. base64ToImg(String base64Strings)
  4. decodeImage(String encoded)
  5. decodeImage(String imageString)
  6. decodeToImage(String imageString)
  7. decodeToImage(String imageString, String pathFile)