English 中文(简体)
如何将沥青阵列转换成java的形象?
原标题:how to convert byte array to image in java?

我正在 Java开发一个网络应用程序。 在这项申请中,我在 Java建立了网络服务。 在这一网络服务中,我制作了一个网络方法,以基64格式把图像清单归来。 这种方法的返回类型是Vector。 在网络服务测试器中,I可将SOAP的答复视为xsi:type=”xs:base64Binary。 然后,我在申请中称之为这一网络方法。 我使用了以下法典:

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

我的法典中是否有任何错误? 或者是否还有其他办法以实际格式塑造形象? 你们能否向我提供我能够解决上述问题的守则或联系?

注:我已经放弃了这一问题,我ug想尝试以下法典:

Object next = iter.next(); 
System.out.println(next.getClass()) 

I tried this code and got the output as byte[] from webservice. but I am not able to convert this byte array to actual image. is there any other way to bring the image in actual format? Can you provide me the code or link through which I can resolve the above issue?

问题回答

你们可以检查这一链接,提供有关将图像转换到拜特和拜特[]图像的信息。 希望有助于你们。

http://www.programcreek.com/2009/02/java-convert-image-to-byte-array-convert-byte-array-to-image/“rel=” http://www.programcreek.com/2009/02/java-convert-image-to-byte-array-convert-byte-array-to-image/。

转换使用基地64.decode;

String base64String = (String)itr.next();
byte[] bytearray = Base64.decode(base64String);

BufferedImage imag=ImageIO.read(bytearray);

我不熟悉你试图做些什么,但我可以说:<条码>:标准确实有一个构造,使用<条码>。

如果我正确理解你的话,你就试图填写<代码>。 String s = (String) byteArray;, 其中当然有t work。 页: 1

审视实际错误信息:

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

I m 说perhaps 您打算:

String img = new String(itr.next());




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签