【发布时间】:2013-12-12 20:33:06
【问题描述】:
我必须将图像 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();
}
【问题讨论】:
-
您正在尝试将 URL 解码为图像。 URL 告诉你图片在哪里!
-
见this answer。如果您无法从中获得帮助,请发布SSCCE。