当前位置: 首页 > news >正文

有人在相亲网站骗人做传销做公众号一般在哪个网站照片

有人在相亲网站骗人做传销,做公众号一般在哪个网站照片,wordpress使用插件下载,wordpress更改主题生成简单的验证码图片 几个简单使用到的类具体实现VerifyCode.classVerifyCodeUtil.classUtilTest.class 测试结果 几个简单使用到的类 BufferedImage : 图像 Graphics2D :图像的上下文 Color : 颜色对象 Font : 字体对象 具体信息大家可以查…

生成简单的验证码图片

  • 几个简单使用到的类
  • 具体实现
    • VerifyCode.class
    • VerifyCodeUtil.class
    • UtilTest.class
  • 测试结果

几个简单使用到的类

BufferedImage : 图像
Graphics2D :图像的上下文
Color : 颜色对象
Font : 字体对象
具体信息大家可以查一下JDK文档。我用的是这个 这个。

具体实现

VerifyCode.class

包含了验证码图片的基本信息,包括但不局限于图片的尺寸、背景颜色、干扰线的数目,干扰线的颜色、验证码的格式、验证码的颜色等等。

import java.awt.*;
import java.util.Random;/*** @author 三文鱼* @title 验证码实体类* @description 包含验证码的必要信息* @date 2022/4/26**/
public class VerifyCode {//图片的宽、高private int width;private int height;//干扰线的条数private int lineCount;//干扰线的颜色private Color lineColor;//干扰线的长度private int lineLength;//验证码背景颜色private Color bgColor;//验证码颜色private Color codeColor;//验证码类型 字符、数字、或者字符数字的随机组合private int codeType;//旋转角度private int angle;//字体private Font font;//用于产生随机颜色和数字private static Random random;public int getWidth() {return width;}public void setWidth(int width) {this.width = width;}public int getHeight() {return height;}public void setHeight(int height) {this.height = height;}public int getLineCount() {return lineCount;}public void setLineCount(int lineCount) {this.lineCount = lineCount;}public Color getBgColor() {return bgColor;}public void setBgColor(Color bgColor) {this.bgColor = bgColor;}public Color getCodeColor() {return codeColor;}public void setCodeColor(Color codeColor) {this.codeColor = codeColor;}public int getCodeType() {return codeType;}public void setCodeType(int codeType) {this.codeType = codeType;}public int getAngle() {return angle;}public void setAngle(int angle) {this.angle = angle;}public Font getFont() {return font;}public void setFont(Font font) {this.font = font;}public static Random getRandom() {return random;}public static void setRandom(Random random) {VerifyCode.random = random;}public Color getLineColor() {return lineColor;}public void setLineColor(Color lineColor) {this.lineColor = lineColor;}public int getLineLength() {return lineLength;}public void setLineLength(int lineLength) {this.lineLength = lineLength;}static {random = new Random();}public VerifyCode() {}//不产生干扰线public VerifyCode(int width, int height) {this.width = width;this.height = height;}public VerifyCode(int width, int height, int lineCount) {this.width = width;this.height = height;this.lineCount = lineCount;}public VerifyCode(int width, int height, int lineCount , int codeType) {this.width = width;this.height = height;this.lineCount = lineCount;this.codeType = codeType;}public VerifyCode(int width, int height, int lineCount , int codeType , int angle) {this.width = width;this.height = height;this.lineCount = lineCount;this.codeType = codeType;this.angle = angle;}public VerifyCode(int width, int height, int lineCount, int codeType, int angle, Font font) {this.width = width;this.height = height;this.lineCount = lineCount;this.codeType = codeType;this.angle = angle;this.font = font;}public VerifyCode(int width, int height, int lineCount, Color bgColor) {this.width = width;this.height = height;this.lineCount = lineCount;this.bgColor = bgColor;}public VerifyCode(int width, int height, int lineCount, Color bgColor, Color codeColor) {this.width = width;this.height = height;this.lineCount = lineCount;this.bgColor = bgColor;this.codeColor = codeColor;}public VerifyCode(int width, int height, int lineCount, Color bgColor, Color codeColor, int codeType) {this.width = width;this.height = height;this.lineCount = lineCount;this.bgColor = bgColor;this.codeColor = codeColor;this.codeType = codeType;}public VerifyCode(int width, int height, int lineCount, Color bgColor, Color codeColor, int codeType, int angle) {this.width = width;this.height = height;this.lineCount = lineCount;this.bgColor = bgColor;this.codeColor = codeColor;this.codeType = codeType;this.angle = angle;}public VerifyCode(int width, int height, int lineCount, Color bgColor, Color codeColor, int codeType, int angle, Font font) {this.width = width;this.height = height;this.lineCount = lineCount;this.bgColor = bgColor;this.codeColor = codeColor;this.codeType = codeType;this.angle = angle;this.font = font;}
}

VerifyCodeUtil.class

该类是验证码图片的工具类,用于生成验证码图片,也可以将生成的验证码图片以输出流的方式输出到文件或者相应的response中。

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Random;/*** @author 三文鱼* @title 验证码工具类* @description* @date 2022/4/26**/
public class VerifyCodeUtil {private static final String TARGAET_STRING = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuioplkjhgfdsazxcvbnm0123456789";/** @description 获得验证码图片对象* @author 三文鱼* @date 16:07 2022/4/26 * @param verifyCode* @return java.awt.image.BufferedImage**/public static BufferedImage getVerifyCodeImage(VerifyCode verifyCode) {if (verifyCode == null)return null;if(verifyCode.getWidth() <=105 || verifyCode.getHeight() <= 35) {verifyCode.setWidth(105);verifyCode.setHeight(35);}int width = verifyCode.getWidth();int height = verifyCode.getHeight();//以三原色为底色构建图像final BufferedImage bufferedImage = new BufferedImage(width , height, BufferedImage.TYPE_INT_RGB);final Graphics2D graphics2D = (Graphics2D) bufferedImage.getGraphics();//随机数种子final Random random = VerifyCode.getRandom();//设置默认底色和边框if(verifyCode.getBgColor() != null) {graphics2D.setColor(verifyCode.getBgColor());}else {graphics2D.setColor(Color.WHITE);}//填充颜色graphics2D.fillRect(0 , 0 , verifyCode.getWidth() , verifyCode.getHeight());//绘出边框graphics2D.drawRect(0 , 0 , verifyCode.getWidth()-1 , verifyCode.getHeight() - 1);//生成干扰线int count = verifyCode.getLineCount();//干扰线颜色Color lineColor = verifyCode.getLineColor();//干扰线的长度int lineLength = verifyCode.getLineLength();if (lineLength == 0)lineLength = 1;if(count == 0) {count = 20;}for (int i =0; i <count; i++) {if(lineColor != null) {graphics2D.setColor(lineColor);}else {graphics2D.setColor(getRandomColor(random));}//生成随机的起点坐标int x = random.nextInt(width - 1 - 1);int y = random.nextInt(height - 1 -1);//生成随机的终点坐标int xEnd = x + random.nextInt(lineLength);int yEnd = y + random.nextInt(lineLength);//绘制线条到图像里面graphics2D.drawLine(x, y , xEnd, yEnd);}//获取验证码用于生成图片final String code = getRandomCode(random , 0);//验证码颜色、字体、旋转角度Color fontColor = verifyCode.getCodeColor();Font font = verifyCode.getFont();int angle = verifyCode.getAngle();int rotateAngle = 0;for(int i =0; i < code.length(); i++) {//设置字体颜色if(fontColor == null) {graphics2D.setColor(getRandomColor(random));}else {graphics2D.setColor(fontColor);}//设置字体样式if (font == null) {graphics2D.setFont(getRandomFont(random , height));}else{graphics2D.setFont(font);}int x = (width/5)*i + width/5;if(angle != 0) {//旋转图像rotateAngle = random.nextInt(angle) - angle/2;graphics2D.rotate(Math.toRadians(rotateAngle) ,x  , height/2);}//绘制字符graphics2D.drawString(String.valueOf(code.charAt(i)) , x , height/2);if(angle != 0) {//逆向旋转 将图像转正graphics2D.rotate(-Math.toRadians(rotateAngle) ,x  , height/2);}}graphics2D.dispose();// 图象生效  释放资源return bufferedImage;}/** @description  获取随机的颜色对象* @author 三文鱼* @date 16:07 2022/4/26* @param random* @return java.awt.Color**/public static Color getRandomColor(Random random) {return new Color(random.nextInt(255) , random.nextInt(255), random.nextInt(255));}/** @description 产生随机字符串* @author 三文鱼* @date 16:06 2022/4/26 * @param random* @param type  0-字母  1-数字 2-数字+字母* @return java.lang.String**/public static String getRandomCode(Random random , int type) {StringBuilder stringBuilder = new StringBuilder();int base = 0;int length = 51;//截取数字if(type == 1) {length = 9;base = 52;}//数字 字符串结合if(type == 2) {length = 61;}for(int i =0; i < 4; i++) {stringBuilder.append(TARGAET_STRING .charAt(random.nextInt(length) + base));}return stringBuilder.toString();}/** @description 设置随机字体大小* @author 三文鱼* @date 16:05 2022/4/26 * @param random* @param height* @return java.awt.Font**/public static Font getRandomFont(Random random , int height) {return new Font("楷体" , Font.BOLD , random.nextInt(20) + height/3);}/** @description 将图片以流的形式输出  可以是本地的文件或者是response的输出流* @author 三文鱼* @date 16:05 2022/4/26* @param image* @param out* @return void**/public static void storeImagetoF(BufferedImage image , OutputStream out)  throws IOException {ImageIO.write(image ,"JPEG", out);}
}

UtilTest.class

简单测试类

import java.awt.*;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;/*** @author 三文鱼* @title* @description* @date 2022/4/26**/
public class UtilTest {public static void main(String[] args) {//默认参数生成的验证码图片//VerifyCode verifyCode = new VerifyCode();//自定义参数生成的验证码图片VerifyCode verifyCode = new VerifyCode(300 , 100 , 200 , Color.WHITE , Color.BLACK, 2 , 45);for (int i = 0; i < 5; i++) {try{Thread.sleep(1000);//文件名称String imageName = getNowDate();//输出的完整路径String totalPath = "F:\\学习记录\\image\\" + imageName +".jpg";VerifyCodeUtil.storeImagetoF(VerifyCodeUtil.getVerifyCodeImage(verifyCode) , new FileOutputStream(totalPath));}catch (Exception exception){exception.printStackTrace();}}}/** @description 获取当前的时间作为图片文件名称* @author 三文鱼* @date 16:17 2022/4/26* @return java.lang.String**/public static String getNowDate() {SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");Date date = new Date(System.currentTimeMillis());return simpleDateFormat.format(date);}
}

测试结果

默认生成的验证码文件,由于默认是宽是一百,高是三十,所以放大后会模糊。
在这里插入图片描述
自定义数据生成为验证码图片
在这里插入图片描述

http://www.yayakq.cn/news/486034/

相关文章:

  • 做修图网站电脑配置电信备案新增网站
  • 什么是门户网站赣州网站开发
  • 学校网站开发建设合同代加工厂找订单的网站
  • 得实网站建设济南各社区报备2022
  • 为网站优势网络规划设计师教程(第2版)
  • 成都有哪些做网站开发的大公司自己做网站用什么软件下载
  • 手机网站打开微信登录邓州市建设局网站
  • 上海崇明林业建设有限公司 网站wordpress会员数
  • 成都网站建设思图佳dw网站模板免费下载
  • 网络工程师和做网站哪个难网页创意的再设计
  • 建网站的支付安全网站开发系统设计
  • 传奇世界网页版平台seo和sem哪个工资高
  • 坂田英文网站制作免费图片编辑工具
  • 前端学习网站建设教程做彩票网站能挣到钱吗?
  • 志迅东莞网站建设wordpress 插件 查看
  • 临沂网站备案公司软装
  • 东莞长安做网站义乌缔造网络科技有限公司
  • 网站开发寄什么科目兰州1万人阳性
  • 环保主题静态网站模板下载十大食品公司
  • 网站正在维护中 模板做企业网站有什么用
  • 江苏网站推广网络无极吧最新招聘信息网
  • 呼和浩特网站网站建设网站开发和大数据开发区别
  • 网站做信用认证有必要吗wordpress参考文档
  • 美工素材网站怀化市鹤城区建设局网站
  • 网站建设与运营公司的市场开发方案做电影网站的资源从哪里换
  • 网站建设需要什么能力哪里网站建设联系方式
  • 新浪门户网站是谁做的杭州婚恋网站建设
  • 网站建设多少钱怎么卖怎么创建网页超链接
  • 休闲度假村网站建设方案白沙网站建设的目标
  • 网站模版的优化公司购物网站备案