• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

转换图像用java为Base64

用户头像
it1352
帮助1

问题说明

我需要一个图像对象转换为一个base64对象,以便我可以加载到我的客户端的标记。

I need to convert a image object to a base64 object so I can load it into the tag on my client side.

不过,我似乎无法弄清楚如何退出这个功能。是否有任何人谁拥有一张code为这个,我可以很容易地使用?

However I can't seem to figure out how to pull this off. Is there anyone who has a piece of code for this that I could use easily?

这是我用开启外部图像链接到一个图像对象

This is what I use to turn the external image link into a image object

Image image = null;
URL url = new URL(request.getParameter("hdn_path"));
image = ImageIO.read(url);

不知道如果我要对这个正确的方式。

not sure if I'm going about this the correct way.

正确答案

#1

使用Apache的 IOUtils 和<一个href=\"http://commons.apache.org/proper/commons-$c$cc/apidocs/org/apache/commons/$c$cc/binary/Base64.html\"相对=nofollow> 的Base64

Using Apache IOUtils and Base64:

byte[] imageBytes = IOUtils.toByteArray(new URL("...")));
String base64 = Base64.getEncoder().encodeToString(imageBytes);

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcbhece
系列文章
更多 icon
同类精品
更多 icon
继续加载