在jsp中显示多个BufferedImage [英] Show Multiple BufferedImage in jsp

查看:410
本文介绍了在jsp中显示多个BufferedImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 ArrayList 中有100个 BufferedImage 对象,我想在jsp中显示所有这些图像。

I have 100 BufferedImage object's in ArrayList, i want to show all of these images in a jsp.

<%
  ArrayList<BufferedImage> list = GlobalData.getImageBufferArrayList();
%>

 </head>
 <body>
 <ul>
 <li><img alt="" src=""> </li>//image1
 <li><img alt="" src=""> </li>//image2
 <li><img alt="" src=""> </li>//image3
   ...
   ..
   ...
 </ul>
</body>

我不知道该放什么 src 关于这些图像

I don't know what to put in src on these images

是否可以将图像数据设置为图像的 src 。(就像我们得到的一样)图像数据来自 canvas in html)

Is it possible to put image data as src of image.(Just like we get image data from canvas in html)

或者是他们展示这些图像的任何体面方式。

Or is their any decent way of showing these images.

推荐答案

您必须将图像文件嵌入到HTML文档中,或通过单独的HTTP请求使其可用。对于前者,您可以使用 数据: URI方案。对于后者,您必须在同一个servlet中提供单独的servlet或单独的代码路径,它将为图像文件提供服务。它可以从一些短期缓存中执行,因此您不必再次执行相同的代码来获取这些图像。

You either have to embed the image files into the HTML document, or make it available through separate HTTP requests. For the former you can use the data: URI scheme. For the latter, you have to provide a separate servlet, or a separate code path inside that same servlet, which will serve the image file. It might do so from some short-lived cache, so you won't have to execute the same code again to obtain these images.

通常,嵌入数据具有与图像大小成比例的大小开销,而单独的请求具有与HTTP请求数量成比例的资源开销。对于小图像,前者可能更好,而对于大图像,后者将更快。实现嵌入应该比实现合理的图像缓存更容易,但我不能100%确定是否所有浏览器都支持数据方案。

In general, embedding the data has a size overhead proportional to the size of the image, whereas the separate requests have a resource overhead proportional to the number of HTTP requests. For small images, the former might be better, while for large images the latter will be faster. Implementing the embedding should be easier than implementing a reasonable image cache, but I'm not 100% sure whether all browser support the data scheme.

在任何一种情况下,你都'我必须序列化 首先是一些字节序列的BufferedImage ,可能使用 ImageIO.write 一起使用ByteArrayOutputStream

In either case, you'll have to serialize the BufferedImage to some byte sequence first, probably using ImageIO.write in conjunction with a ByteArrayOutputStream.

这篇关于在jsp中显示多个BufferedImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆