JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Servlet/JSP 討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 Re:沒什麼營養的動態生成圖片 Servlet & JSP [Re:JiaYun]
shasun





發文: 118
積分: 0
於 2006-12-04 18:24 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
來些雜訊, 避免有心人士使用OCR辨識, 呵呵...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Iterator;
 
import javax.imageio.ImageIO;
import javax.imageio.ImageWriter;
import javax.imageio.stream.ImageOutputStream;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
public class DynaImageServlet extends HttpServlet {
 
   public void doGet(HttpServletRequest request, HttpServletResponse response)
         throws ServletException,
         IOException {
 
      try {
         BufferedImage bufferedImage = new BufferedImage(50, 30, BufferedImage.TYPE_INT_RGB);
         Graphics2D bufferedGraphics = bufferedImage.createGraphics();
         bufferedGraphics.setColor(Color.WHITE);
         bufferedGraphics.fillRect(0, 0, 50, 30);
         bufferedGraphics.setColor(Color.BLACK);
         bufferedGraphics.drawRect(5, 5, 40, 20);
 
         String number = Integer.toString((int) (Math.random() * 10000));
         while (number.length() < 4) {
            number = "0" + number;
         }
 
         bufferedGraphics.setFont(new Font("Default", Font.BOLD, 13));
         bufferedGraphics.drawString(number, 10, 20);
 
         for (int i = 0; i < 20; i++) {
            int x = (int) (Math.random() * 40) + 5;
            int y = (int) (Math.random() * 20) + 5;
 
            bufferedGraphics.fillOval(x, y, 1, 1);
         }
 
         response.setContentType("image/jpeg");
         ServletOutputStream outstream = response.getOutputStream();
 
         Iterator ite = ImageIO.getImageWritersByFormatName("jpeg");
         ImageWriter imageWriter = (ImageWriter) ite.next();
 
         ImageOutputStream ios = ImageIO.createImageOutputStream(outstream);
         imageWriter.setOutput(ios);
         imageWriter.write(bufferedImage);
         ios.flush();
         outstream.close();
 
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}
 


reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
27257 [精華] 沒什麼營養的動態生成圖片 Servlet & JSP JiaYun 571 2003-07-03 18:45
21590 Re:沒什麼營養的動態生成圖片 Servlet & JSP iampoya 33 2003-07-03 18:55
16678 Re:沒什麼營養的動態生成圖片 Servlet & JSP uxa 6372 2006-11-30 20:22
14652 Re:沒什麼營養的動態生成圖片 Servlet & JSP ok12360000 176 2007-07-27 23:50
16152 Re:沒什麼營養的動態生成圖片 Servlet & JSP shasun 2209 2006-12-04 18:24
16010 Re:沒什麼營養的動態生成圖片 Servlet & JSP jen3 16 2006-12-07 17:26
21146 Re:沒什麼營養的動態生成圖片 Servlet & JSP koji 288 2003-07-03 19:13
20862 Re:沒什麼營養的動態生成圖片 Servlet & JSP JiaYun 122 2003-07-03 19:18
20823 Re:沒什麼營養的動態生成圖片 Servlet & JSP JiaYun 182 2003-07-03 19:27
20679 Re:沒什麼營養的動態生成圖片 Servlet & JSP koji 72 2003-07-03 19:36
20615 Re:沒什麼營養的動態生成圖片 Servlet & JSP sdargon 79 2003-07-21 17:13
20278 Re:沒什麼營養的動態生成圖片 Servlet & JSP jeff0208 38 2003-07-22 14:31
20290 Re:沒什麼營養的動態生成圖片 Servlet & JSP garbage 26 2003-07-26 06:15
19674 Re:沒什麼營養的動態生成圖片 Servlet & JSP freeman_z 97 2004-07-05 12:30
18434 Re:沒什麼營養的動態生成圖片 Servlet & JSP qboy113011 44 2005-05-11 08:46
18606 Re:沒什麼營養的動態生成圖片 Servlet & JSP qboy113011 94 2005-05-11 21:04
» JWorld@TW »  Servlet/JSP 討論區

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8