Prezados, boa tarde!
Estou com o seguinte código:
public static String convert(String base64String) {
// Decodifica a string Base64 em um array de bytes
byte[] imageBytes = Base64.getDecoder().decode(base64String);
try {
ByteArrayInputStream bis = new ByteArrayInputStream(imageBytes);
BufferedImage image = ImageIO.read(bis);
// Cria um ByteArrayOutputStream para armazenar os bytes da imagem JPG
ByteArrayOutputStream bos = new ByteArrayOutputStream();
// Salva a imagem no formato JPG no ByteArrayOutputStream
ImageIO.write(image, "jpg", bos);
// Codifica os bytes da imagem JPG em formato Base64, add na lista e retorna a
// string resultante
return Base64.getEncoder().encodeToString(bos.toByteArray());
} catch (
IOException e) {
e.printStackTrace();
return null;
}
}
Na linha do BufferedImage image = ImageIO.read(bis) a image está vindo nula eu não sei dizer o por quê? Alguém pode me ajudar. O objetivo desse código é converter Base64 para Imagem.