简体   繁体   English

如何在jsp页面中显示缓冲图像?

[英]How to display a buffered image in a jsp page?

Hai guys, I have a java page and there is a buffered image in it. Hai伙计们,我有一个java页面,里面有一个缓冲图像。 I want to pass this buffered image into a jsp page and i want to display it there. 我想将这个缓冲的图像传递到jsp页面,我想在那里显示它。 Guys so pls help me to do it. 伙计们请帮我做。 I am new in java. 我是java的新手。 so help me with simple codes. 所以用简单的代码帮我。 Thanks in advance. 提前致谢。

Here is a sample program taken from this post . 下面是抽取的样本程序这个职位 It works fine. 它工作正常。

<%@page import="java.awt.image.BufferedImage"%>
<%@page import="javax.imageio.ImageIO"%>
<%@page import="java.io.*"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
BufferedImage bImage = ImageIO.read(new File("/home/visruth/Desktop/Visruth.jpg"));//give the path of an image
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write( bImage, "jpg", baos );
baos.flush();
byte[] imageInByteArray = baos.toByteArray();
baos.close();
String b64 = javax.xml.bind.DatatypeConverter.printBase64Binary(imageInByteArray);
%>

<div>
    <p>As of v6, Java SE provides JAXB</p>
    <img src="data:image/jpg;base64, <%=b64%>" alt="Visruth.jpg not found" />
</div>          
</body>
</html>
  1. you can write buffered image to some public web space and provide src to that in img tag 您可以将缓冲的图像写入某个公共Web空间,并在img标记中提供src

  2. provide src as servlet and output the image directly from the servlet 提供src作为servlet并直接从servlet输出图像

Also See 另见

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM