我必须将图片网址转换为图片。为此,我尝试将编码转换为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();
}
答案 0 :(得分:0)
我必须将图片网址转换为图片。
如果这是你唯一的要求,那会这样做吗?
URL url = new URL("www.example.com/image.png");
BufferedImage image = ImageIO.read(url);
File outputfile = new File("E:\\saved.png");
ImageIO.write(image, "png", outputfile);