|
@@ -1,8 +1,6 @@
|
|
|
package cn.com.taiji.commAll;
|
|
|
|
|
|
-import java.awt.Color;
|
|
|
-import java.awt.Font;
|
|
|
-import java.awt.Graphics;
|
|
|
+import java.awt.*;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.IOException;
|
|
|
import java.security.Principal;
|
|
@@ -37,26 +35,23 @@ public class HomeController {
|
|
|
*/
|
|
|
@RequestMapping(value = "/image", method = RequestMethod.GET)
|
|
|
public String image(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+
|
|
|
response.setHeader("Pragma","No-cache");
|
|
|
response.setHeader("Cache-Control","no-cache");
|
|
|
response.setDateHeader("Expires",0);
|
|
|
- BufferedImage img = new BufferedImage(68, 22,
|
|
|
-
|
|
|
- BufferedImage.TYPE_INT_RGB);
|
|
|
+ BufferedImage img = new BufferedImage(68, 22, BufferedImage.TYPE_INT_ARGB);
|
|
|
|
|
|
- // 得到该图片的绘图对象
|
|
|
-
|
|
|
- Graphics g = img.getGraphics();
|
|
|
+ // 得到该图片的绘图对象
|
|
|
+ Graphics2D g = img.createGraphics();
|
|
|
|
|
|
Random r = new Random();
|
|
|
|
|
|
- Color c = new Color(200, 150, 255);
|
|
|
-
|
|
|
- g.setColor(c);
|
|
|
+ Color c = new Color(0, 0, 0, 0);
|
|
|
+ g.setColor(c);
|
|
|
|
|
|
// 填充整个图片的颜色
|
|
|
|
|
|
- g.fillRect(0, 0, 68, 22);
|
|
|
+ g.fillRect(0, 0, 68, 22);
|
|
|
|
|
|
// 向图片中输出数字和字母
|
|
|
|
|
@@ -80,16 +75,12 @@ public class HomeController {
|
|
|
request.getSession().setAttribute("j_captcha", sb.toString());
|
|
|
|
|
|
try {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
response.setHeader("content-type","image/jpeg");
|
|
|
response.setContentType("image/jpeg");
|
|
|
response.setHeader("Param","no-cache");
|
|
|
response.setHeader("Cache-Control", "no-cache");
|
|
|
response.setIntHeader("Expries",-1);
|
|
|
-
|
|
|
- ImageIO.write(img, "JPEG", response.getOutputStream());
|
|
|
+ ImageIO.write(img, "PNG", response.getOutputStream());
|
|
|
} catch (IOException e) {
|
|
|
// TODO Auto-generated catch block
|
|
|
e.printStackTrace();
|