Java BufferedImage from String base64StringToImage(String imageString)

Here you can find the source of base64StringToImage(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 base64StringToImage(String imageString) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014 Open Door Logistics (www.opendoorlogistics.com)
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v3
 * which accompanies this distribution, and is available at http://www.gnu.org/licenses/lgpl.txt
 ******************************************************************************/

import java.awt.image.BufferedImage;

import java.io.ByteArrayInputStream;

import javax.imageio.ImageIO;

import sun.misc.BASE64Decoder;

public class Main {
    /**//  w w w  .  ja v a2s. com
     * Decode string to image
     * 
     * @param imageString
     *            The string to decode
     * @return decoded image
     */
    public static BufferedImage base64StringToImage(String imageString) {
        BufferedImage ret = null;
        byte[] imageByte;
        try {
            BASE64Decoder decoder = new BASE64Decoder();
            imageByte = decoder.decodeBuffer(imageString);
            ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);
            ret = ImageIO.read(bis);
            bis.close();
        } catch (Throwable e) {

        }
        return ret;
    }
}

Related

  1. base64StringToImage(String imageString)
  2. base64StringToImg(final String base64String)
  3. base64ToImage(final String data, final int width, final int height)
  4. base64ToImage(String base64)