Here you can find the source of decodeToImage(String imageString, String pathFile)
Parameter | Description |
---|---|
imageString | The string to decode |
Parameter | Description |
---|---|
IOException | an exception |
public static BufferedImage decodeToImage(String imageString, String pathFile) throws IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.io.ByteArrayInputStream; import java.io.File; import java.awt.image.BufferedImage; import javax.imageio.ImageIO; import org.apache.commons.codec.binary.Base64; public class Main { /**//w w w. ja v a2 s . co m * Decode string to image * @param imageString The string to decode * @return decoded image. * @throws IOException */ public static BufferedImage decodeToImage(String imageString, String pathFile) throws IOException { BufferedImage image = null; byte[] imageByte; try { imageByte = Base64.decodeBase64(imageString); ByteArrayInputStream bis = new ByteArrayInputStream(imageByte); image = ImageIO.read(bis); bis.close(); } catch (Exception e) { e.printStackTrace(); } if (image != null) { ImageIO.write(image, "jpg", new File(pathFile)); } return image; } }