我必须将图像 URL 转换为图像。为此,我尝试了以下编码以将 base64 转换为图像。在调试代码时,“Bufferedimage image”在ByteArrayInputStream bis=new ByteArrayInputStream(imagebyte)
. 我能做些什么?
String imageStr = request.getParameter("imgURL");
BufferedImage image = null;
try {
BASE64Decoder decoder = new BASE64Decoder();
byte[] imageByte = decoder.decodeBuffer(imageStr);
ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);
image = ImageIO.read(bis);
File outputfile = new File("E:\\saved.png");
ImageIO.write(image, "png", outputfile);
bis.close();
} catch (Exception e) {
e.printStackTrace();
}