当前位置 : 主页 > 编程语言 > c++ >

图形验证码生成工具

来源:互联网 收集:自由互联 发布时间:2021-07-03
YZM.java package lxycx.xc.util.run;import java.awt.Color;import java.awt.Font;import java.awt.Graphics2D;import java.awt.image.BufferedImage;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.Outpu
YZM.java
package lxycx.xc.util.run;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Random;

import javax.imageio.ImageIO;

import org.apache.log4j.Logger;

/**
 * 图形验证码生成工具
 * */
public class YZM {
	private static Logger log = Logger.getLogger(YZM.class);
	private int imgWidth = 16;
	private int imgHeight =26;
	private String type = "楷体";
	
	
	private YZM(){}
	
	private YZM(String type,int imgWidth,int imgHeight){
		this.type=type;
		this.imgHeight = imgHeight;
		this.imgWidth = imgWidth;
	}
	
	public static YZM getYZM(){
		return new YZM();
	}
	
	public static YZM getYZM(String type,int imgWidth,int imgHeight){
		return getYZM(type, imgWidth, imgHeight);
	}
	
	
	
	/**
	 * 生成一个验证码,返回一个对应的字符串
	 * @param out 验证码输出源
	 * @param size 验证码长度
	 * */
	public String imageYzm(OutputStream out,int size){
		
		StringBuilder sb = new StringBuilder();
		for(int i=0;i
网友评论