Java BufferedImage from String decodeImage(String encoded)

Here you can find the source of decodeImage(String encoded)

Description

create an image from the given ascii-encoded representation

License

Apache License

Parameter

Parameter Description
encoded ascii-encoded image representation

Exception

Parameter Description
IOException if there are errors creating the image

Return

image

Declaration

public static BufferedImage decodeImage(String encoded) throws IOException 

Method Source Code


//package com.java2s;
/*//ww  w .  j ava  2 s.  c om
 * Copyright 2010 Alternate Computing Solutions Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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

import java.io.IOException;
import javax.imageio.ImageIO;
import sun.misc.BASE64Decoder;

public class Main {
    /**
     * create an image from the given ascii-encoded representation
     *
     * @param encoded ascii-encoded image representation
     * @return image
     * @throws IOException if there are errors creating the image
     */
    public static BufferedImage decodeImage(String encoded) throws IOException {
        BASE64Decoder decoder = new BASE64Decoder();
        byte[] bytes = decoder.decodeBuffer(encoded);
        ByteArrayInputStream input = new ByteArrayInputStream(bytes);
        return ImageIO.read(input);
    }
}

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)
  5. base64ToImg(String base64Strings)
  6. decodeImage(String imageString)
  7. decodeToImage(String imageString)
  8. decodeToImage(String imageString)
  9. decodeToImage(String imageString, String pathFile)