首页 > 开发 > 综合 > 正文

通过处理数据流在网页中显示图像

2024-07-21 02:14:08
字体:
来源:转载
供稿:网友

动态加工原有的图像文件,显示到网页
getimage.javaservlet 映射为/getimage
import java.io.*;import javax.servlet.*;import javax.servlet.http.*;

public class getimage extends httpservlet{ public void doget(httpservletrequest request,httpservletresponse response) throws ioexception, servletexception {   //通过request中的参数取得file    string img=request.getparameter("imgid");  file file=new file("d://mypath//"+img);  inputstream fis=new fileinputstream(file);  int length=(int)file.length();    byte[] image=new byte[length];    fis.read(image);    {  //加工jpg  //myutil.draw(image);  }  //jpg回显    if (file!=null)  {   response.setcontenttype("image/jpg");   outputstream output = response.getoutputstream();   response.setcontentlength(image.length);   output.write(image);   output.close();   response.reset();  } } public void dopost(httpservletrequest request,httpservletresponse response) throws ioexception, servletexception{  doget(request,response);

 } }

view.jsp

<html> <head> <meta http-equiv="content-type" content="text/html; charset=gb2312"><%@ page language="java"%><%@ page contenttype="text/html; charset=gb2312"%>  <title>drawjpg test</title> </head> <body>  <div align=center>   <img src=http://www.163design.net/j/e/"getimg?imgid=aa.jpg" >    </div> </body></html>


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表