将多个图像写入 byteArrayOutputstream

Writing multiple images to byteArrayOutputstream

我需要将多个图像添加到输出流并在 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