servlet_image

转载 2007年09月25日 09:45:00
import java.io.*;

import java.awt.*;

import java.awt.image.*;

 

import javax.servlet.*;

import javax.servlet.http.*;

 

import com.sun.image.codec.jpeg.*;

 

/**

* @author Liao Xue Feng

*/

public class CreateImageServlet

extends HttpServlet

{

 

 protected void doGet(HttpServletRequest request,HttpServletResponse response) throws  ServletException,IOException

 {

  response.setContentType("image/jpeg");

  createImage(response.getOutputStream());

 }

 

 private void createImage(OutputStream out)

{

  int width = 100;

  int height = 100;

  BufferedImage bi =new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);

  Graphics2D g = bi.createGraphics();

  // set background:

  g.setBackground(Color.BLUE);

  g.clearRect(0, 0, width, height);

  // set fore color:

  g.setColor(Color.RED);

  // start draw:

  g.drawLine(0, 0, 99, 199);

  // end draw:

  g.dispose();

  bi.flush();

  // encode:

  JPEGImageEncoder encoder= JPEGCodec.createJPEGEncoder(out);

  JPEGEncodeParam param= encoder.getDefaultJPEGEncodeParam(bi);

  param.setQuality(1.0f, false);

  encoder.setJPEGEncodeParam(param);

  try {

   encoder.encode(bi);

  }

  catch(IOException ioe) {

   ioe.printStackTrace();

  }

 }

}

 
最后将Servlet编译,注册到web.xml中,映射路径/CreateImage,写一个简单index.html测试

 

html><head></head

body

img src="CreateImage"

/body></html

 

相关文章推荐

ImageLoader_ _Universal-Image-Loader完全解析(一)之介绍与使用详解

转载请标明出处: http://blog.csdn.net/developer_jiangqq/article/details/50439814 本文出自:【江清清的博客】 尊重原创,转载请...

universal-image-loader-1.9.5.jar

  • 2017-10-10 17:31
  • 158KB
  • 下载

[LeetCode-Java]48. Rotate Image

You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).解1...

Linear Spatial Pyramid Matching Using Sparse Coding for Image Classification 理解

最近又重新阅读了Yang Jianchao的文章“Linear Spatial Pyramid Matching Using Sparse Coding for Image Classificatio...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)