点击这里给我发消息 点击这里给我发消息

JSP中在内存中生成的图片显示到页面中

添加时间:2013-12-7
    相关阅读: 页面 HTML JSP

  <%@ page autoFlush="false" import="java.awt.*,java.awt.image.*,com.sun.image.codec.jpeg.*,java.util.*"%>
  <%
    String ImageStr = request.getParameter("ID_Text");
    if(ImageStr==null || ImageStr.equals(""))
    {
      response.setContentType("text/html; charset=gb2312");
   %>
  <HTML>
   <HEAD>
   <title>Http://www.lionsky.net</title>
   <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
   </HEAD>
   <body>
   <form id="Form1" method="post">
    <input type="text" id="ID_Text" name=ID_Text>
    <input type=submit value="GO">
   </form>
   </body>
  </HTML>
  
  <%
      }
      else
      {
      out.clear();
      response.setContentType("image/jpeg");
      response.addHeader("pragma","NO-cache");
      response.addHeader("Cache-Control","no-cache");
      response.addDateHeader("Expries",0);
      int width=300, height=100;
      BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
      Graphics g = image.getGraphics();
      //以下填充背景颜色
      g.setColor(Color.lightGray);
      g.fillRect(0, 0, width, height);
      String random="random";
      //以下设置前景色
      g.setColor(Color.BLACK);
      g.drawString("Http://www.lionsky.net",10,20);
      g.drawString("Author:Lion[lion-a@sohu.com]",10,40);
      g.drawLine(10,50,290,50);
      g.drawString(ImageStr,10,70);
      g.dispose();
      ServletOutputStream outStream = response.getOutputStream();
      JPEGImageEncoder encoder =JPEGCodec.createJPEGEncoder(outStream);
      encoder.encode(image);
      outStream.close();
    }
  
  %>
咨询热线:020-85648757 85648755 85648616 0755-27912581 客服:020-85648756 0755-27912581 业务传真:020-32579052
广州市网景网络科技有限公司 Copyright◎2003-2008 Veelink.com. All Rights Reserved.
广州商务地址:广东省广州市黄埔大道中203号(海景园区)海景花园C栋501室
= 深圳商务地址:深圳市宝源路华丰宝源大厦606
研发中心:广东广州市天河软件园海景园区 粤ICP备05103322号 工商注册