我需要将图像对象转换为 base64 对象,以便我可以将其加载到客户端的标签中。
但是我似乎无法弄清楚如何实现这一点。有没有人有一段我可以轻松使用的代码?
这就是我用来把外部图片链接变成图片对象的
Image image = null;
URL url = new URL(request.getParameter("hdn_path"));
image = ImageIO.read(url);
不确定我的做法是否正确。
最佳答案
byte[] imageBytes = IOUtils.toByteArray(new URL("...")));
String base64 = Base64.getEncoder().encodeToString(imageBytes);
关于java - 使用java将图像转换为base64,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28268511/