我需要将多个图像添加到输出流并在 JSF 中显示这些图像。
Ex 代码:
List<inputStream> images = list of inputstream - each image is one input stream
ByteArrayOutputStream stream = new ByteArrayOutputStream()
for(inputStream iStream: images){
stream.write(IOUtils.toByteArray(iStream);
}
return stream.toByteArray();
现在它只显示第一张图片,不显示其余图片。
请在这里帮助我传递多个图像并在 jsp 中显示。
最佳答案
你可以这样尝试:
ByteArrayOutputStream stream = new ByteArrayOutputStream();
List<byte[]> imagesByteList = new List<byte[]>;
for(inputStream iStream: images){
stream.write(IOUtils.toByteArray(iStream);
imagesByteList.add(stream.toByteArray());
stream.reset();
}
return imagesByteList; // here you get all your image in bytes array form
关于java - 将多个图像写入 byteArrayOutputstream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29786740/