gpt4 book ai didi

java - 如何将从 Web 服务接收到的 Binary64 格式的图像转换为实际图像?

转载 作者:行者123 更新时间:2023-12-02 00:52:30 26 4
gpt4 key购买 nike

我正在用 Java 开发一个 Web 应用程序。在该应用程序中,我用 Java 创建了 Web 服务。在该 Web 服务中,我创建了一种 Web 方法,它以 Base64 格式返回图像列表。该方法的返回类型是Vector。在 Web 服务测试器中,我可以看到 SOAP 响应为 xsi:type="xs:base64Binary"。然后我在我的应用程序中调用这个 webmethod。我使用了以下代码:

SBTSWebService webService = null;
List imageArray = null;
List imageList = null;
webService = new SBTSWebService();
imageArray = webService.getSBTSWebPort().getAddvertisementImage();
Iterator itr = imageArray.iterator();
while(itr.hasNext())
{
String img = (String)itr.next();
byte[] bytearray = Base64.decode(img);
BufferedImage imag=ImageIO.read(new ByteArrayInputStream(bytearray));
imageList.add(imag);
}

在此代码中我收到错误:

java.lang.ClassCastException: [B cannot be cast to java.lang.String" on line String img = (String)itr.next();

我的代码有错误吗?或者还有其他方法可以将图像转换为实际格式吗?您能给我提供解决上述问题的代码或链接吗?

最佳答案

类型指示符[B告诉您,您已收到一个字节数组,而不是来自迭代器的字符串。我无法判断这些字节是 Base64 字符串的有线格式(因此需要使用适当的编码创建一个新字符串),还是已经解码的 Base64 blob。

关于java - 如何将从 Web 服务接收到的 Binary64 格式的图像转换为实际图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2424205/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com