旋转的验证码
来源:互联网 发布:网络售彩何时恢复 编辑:程序博客网 时间:2024/05/22 05:08
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
/**
* 在内存中生成图片,没有设置背景颜色,画填充矩形,并且和纸大小相同,矩形有颜色
* 获取笔的对象,设置颜色
* 先准备好数据,随机生成4个字符,把字符画到纸上
* 画干扰线
* 把内存中的图片输出到客户端上
*/
int width = 120;
int height = 30;
//在内存中生成图片
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
//获取画笔的对象
Graphics2D g = (Graphics2D) image.getGraphics();
//设置颜色
g.setColor(Color.GRAY);
//画填充矩形
g.fillRect(0, 0, width, height);
//设置颜色
g.setColor(Color.BLUE);
//画边框
g.drawRect(0, 0, width-1, height-1);
//准备数据,随机获取4个字符
String words = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM789561230";
//设置颜色
g.setColor(Color.YELLOW);
//设置字体
g.setFont(new Font("隶书",Font.BOLD,20));
Random random = new Random();
int x = 20;
int y = 20;
for(int i = 0; i < 4; i++){
/**
* Theta弧度
* 弧度 = 角度*Math.PI/180
* 获取正负30之间的角度
*/
int jiaodu = random.nextInt(60)-30;
double hudu = jiaodu*Math.PI/180;
g.rotate(hudu, x, y);
//获取下标
int index = random.nextInt(words.length());
char ch = words.charAt(index);
//写字符串
g.drawString(""+ch, x, y);
//返回到0位置转
g.rotate(-hudu, x, y);
x = x+20;
}
//设置颜色
g.setColor(Color.GREEN);
int x1, y1, x2, y2;
for(int i = 0; i < 4; i++){
//画干扰线
x1 = random.nextInt(width);
y1 = random.nextInt(height);
x2 = random.nextInt(width);
y2 = random.nextInt(height);
g.drawLine(x1, y1, x2, y2);
}
//把内存中的图片输出到浏览器端
ImageIO.write(image, "jpg", response.getOutputStream());
}
throws ServletException, IOException {
/**
* 在内存中生成图片,没有设置背景颜色,画填充矩形,并且和纸大小相同,矩形有颜色
* 获取笔的对象,设置颜色
* 先准备好数据,随机生成4个字符,把字符画到纸上
* 画干扰线
* 把内存中的图片输出到客户端上
*/
int width = 120;
int height = 30;
//在内存中生成图片
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
//获取画笔的对象
Graphics2D g = (Graphics2D) image.getGraphics();
//设置颜色
g.setColor(Color.GRAY);
//画填充矩形
g.fillRect(0, 0, width, height);
//设置颜色
g.setColor(Color.BLUE);
//画边框
g.drawRect(0, 0, width-1, height-1);
//准备数据,随机获取4个字符
String words = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM789561230";
//设置颜色
g.setColor(Color.YELLOW);
//设置字体
g.setFont(new Font("隶书",Font.BOLD,20));
Random random = new Random();
int x = 20;
int y = 20;
for(int i = 0; i < 4; i++){
/**
* Theta弧度
* 弧度 = 角度*Math.PI/180
* 获取正负30之间的角度
*/
int jiaodu = random.nextInt(60)-30;
double hudu = jiaodu*Math.PI/180;
g.rotate(hudu, x, y);
//获取下标
int index = random.nextInt(words.length());
char ch = words.charAt(index);
//写字符串
g.drawString(""+ch, x, y);
//返回到0位置转
g.rotate(-hudu, x, y);
x = x+20;
}
//设置颜色
g.setColor(Color.GREEN);
int x1, y1, x2, y2;
for(int i = 0; i < 4; i++){
//画干扰线
x1 = random.nextInt(width);
y1 = random.nextInt(height);
x2 = random.nextInt(width);
y2 = random.nextInt(height);
g.drawLine(x1, y1, x2, y2);
}
//把内存中的图片输出到浏览器端
ImageIO.write(image, "jpg", response.getOutputStream());
}
0 0
- 旋转的验证码
- 可以旋转文字的验证码
- 带字符旋转的彩色 java 验证码
- php生成扭曲及旋转的验证码图片
- java图片验证码包括文字和图片的旋转
- java图片验证码包括文字和图片的旋转
- 验证Hu矩的旋转不变性
- 【React Native 实战】旋转图片验证码
- 生成图片彩色验证码(附带验证码旋转)
- 生成图片彩色验证码(附带验证码旋转)
- 生成图片彩色验证码(附带验证码旋转)
- ASP.NET软件开发_ 旋转的可视验证码图象_源码
- 验证码的验证
- 验证码的验证
- paip.验证码识别---扭曲与旋转文字
- php 生成验证码(带旋转和干扰线条)
- PHP验证码:随机扭曲、旋转、变形…
- 随机验证码(线条,旋转,干扰线)
- Linux2.6X内核中文件相关结构体总结
- Obect-c AutoReleasePool
- SAR ADC_逐次逼近型ADC
- 关于activity之间通过广播传递!
- c++第三次作业
- 旋转的验证码
- C#调用C++/C库中的函数
- 网易编程题一,回文序列(贪心法)
- 树莓派上的软件安装和卸载命令汇总
- java8函数式编程之六--Function接口
- UnityShader官方案例之表面着色器光照示例
- J2EE规范
- 获取缓存数据,并清理
- android实现下拉框(spinner),自定义大小颜色背景位置