如何使用 HTML 标签向 JSP 页面显示以字节为单位的图像? [英] How to display an image which is in bytes to JSP page using HTML tags?

查看:35
本文介绍了如何使用 HTML 标签向 JSP 页面显示以字节为单位的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 ByteArrayOutputStream,它包含一个以字节为单位的 JPEG 图像.我的要求是在 JSP 页面中显示该图像(使用HTML 标签).我该怎么做?

I have ByteArrayOutputStream which contains a JPEG image in bytes. My requirement is to display that image in a JSP page (to display the image in the frontend using HTML tags). How do I do that?

我已经提到了 BufferedImage 类,但它让我感到困惑,因为我是新手.

I have referred the BufferedImage class, but it is confusing for me because I am new to this.

推荐答案

如果图片不是太大,可以如下操作.

If the image is not too big, you can do it as follows.

<img src="data:image/jpg;base64,iVBORw0KGgoAAAANS..." />

其中 iVBORw0KGgoAAAANS... 是 Base64 编码的字节.

Where iVBORw0KGgoAAAANS... is the Base64 encoded bytes.

Base64 编码可以使用库完成,例如 Ostermiller Java Utilities 的 Base64 Java 库org.apache.commons.codec.binary.Base64.

Base64 encoding can be done with a library, like Ostermiller Java Utilities' Base64 Java Library or org.apache.commons.codec.binary.Base64.

这篇关于如何使用 HTML 标签向 JSP 页面显示以字节为单位的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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