【问题标题】:How to convert Base64(imageurl) to an image如何将 Base64(imageurl) 转换为图像
【发布时间】: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

标签: java base64 imageurl


【解决方案1】:

我必须将图像 URL 转换为图像。

如果这是您唯一的要求,那么这样做可以吗?

 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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-03
    • 1970-01-01
    • 2015-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-26
    相关资源
    最近更新 更多