我这个属于二次开发,这段代码暂时还不懂,现需要将现有代码改成算式验证码,该如何更改? 之前用的验证码都是用graphics这个画的,但是这个需要存放session,在我们系统,不知道怎么回事,session会销毁,所以就在原有代码上修改了,下面这段代码该怎样改成算式验证码???10以内加减那种
package com.auchan.captcha.util;
import com.octo.captcha.service.captchastore.FastHashMapCaptchaStore;
import com.octo.captcha.service.image.DefaultManageableImageCaptchaService;
import com.octo.captcha.service.image.ImageCaptchaService;
public class CaptchaServiceSingleton {
private static ImageCaptchaService captchaService1 = new DefaultManageableImageCaptchaService(
new FastHashMapCaptchaStore(),
new MyImageCaptchaEngine(),
180,
100000,
75000
);
public static ImageCaptchaService getInstance(){
if (captchaService1==null){
captchaService1=new DefaultManageableImageCaptchaService(
new FastHashMapCaptchaStore(),
new MyImageCaptchaEngine(),
180,
100000,
75000
);
}
return captchaService1;
}
}
package com.auchan.captcha.util;
import java.awt.Color;
import java.awt.Font;
import java.awt.image.ImageFilter;
import java.util.Random;
import com.octo.captcha.component.image.backgroundgenerator.BackgroundGenerator;
import com.octo.captcha.component.image.backgroundgenerator.UniColorBackgroundGenerator;
import com.octo.captcha.component.image.color.RandomRangeColorGenerator;
import com.octo.captcha.component.image.deformation.ImageDeformation;
import com.octo.captcha.component.image.deformation.ImageDeformationByFilters;
import com.octo.captcha.component.image.fontgenerator.FontGenerator;
import com.octo.captcha.component.image.fontgenerator.RandomFontGenerator;
import com.octo.captcha.component.image.textpaster.DecoratedRandomTextPaster;
import com.octo.captcha.component.image.textpaster.TextPaster;
import com.octo.captcha.component.image.textpaster.textdecorator.BaffleTextDecorator;
import com.octo.captcha.component.image.textpaster.textdecorator.LineTextDecorator;
import com.octo.captcha.component.image.textpaster.textdecorator.TextDecorator;
import com.octo.captcha.component.image.wordtoimage.DeformedComposedWordToImage;
import com.octo.captcha.component.image.wordtoimage.WordToImage;
import com.octo.captcha.component.word.wordgenerator.RandomWordGenerator;
import com.octo.captcha.component.word.wordgenerator.WordGenerator;
import com.octo.captcha.engine.image.ListImageCaptchaEngine;
public class MyImageCaptchaEngine extends ListImageCaptchaEngine {
//验证码的Key
private static Random random = new Random();
@Override
protected void buildInitialFactories() {
WordGenerator wgen = new RandomWordGenerator("abcdefghijklmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ123456789");
RandomRangeColorGenerator cgen = new RandomRangeColorGenerator(
new int[] { 0, 150 }, new int[] { 0, 150 },
new int[] { 0, 150 });
RandomRangeColorGenerator lineColors = new RandomRangeColorGenerator(
new int[] { 150, 255 }, new int[] { 150, 255 }, new int[] {
150, 255 });
BaffleTextDecorator baffleTextDecorator = new BaffleTextDecorator(2,cgen);//气泡干扰
TextPaster textPaster = new DecoratedRandomTextPaster(new Integer(4),
new Integer(4), cgen, true,
new TextDecorator[] { new BaffleTextDecorator(new Integer(0), Color.black) });
LineTextDecorator lineTextDecorator = new LineTextDecorator(1,cgen);//曲线干扰
TextDecorator[] textDecorators = new TextDecorator[1];
Color c = getRandColor(200, 250);
Color c1 = getRandColor(160, 200);
//过滤器
BackgroundGenerator backgroundGenerator = new UniColorBackgroundGenerator(new Integer(140), new Integer(40),new Color(238,238,238));
ImageDeformation postDef = new ImageDeformationByFilters(new ImageFilter[] {});
ImageDeformation backDef = new ImageDeformationByFilters(new ImageFilter[] {});
ImageDeformation textDef = new ImageDeformationByFilters(new ImageFilter[] {});
Font[] fontsList = new Font[] { new Font("Arial", 0, 17),
new Font("Tahoma", 0, 17), new Font("Verdana", 0, 17),
new Font("Helvetica", 0, 17), new Font("宋体", 0, 17),
new Font("黑体", 0, 17), new Font("幼圆", 0, 17) };
FontGenerator fontGenerator = new RandomFontGenerator(new Integer(15), new Integer(25), fontsList);
WordToImage wordToImage = new DeformedComposedWordToImage(fontGenerator, backgroundGenerator, textPaster,backDef, textDef, postDef);
this.addFactory(new MyGimpyFactory(wgen, wordToImage));
}
private static Color getRandColor(int fc, int bc) {
if (fc > 255)
fc = 255;
if (bc > 255)
bc = 255;
int r = fc + random.nextInt(bc - fc);
int g = fc + random.nextInt(bc - fc);
int b = fc + random.nextInt(bc - fc);
return new Color(r, g, b);
}
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。